What I'm trying to do: I want to have a tree and every few seconds an Apple falls down from that tree. Player can "pick up" that Apple. If more players are in the game, player who picks up the most apples, wins.
What I have: I have a tree and apples are falling down. Until here it works perfect. Player can pick up an apple - if he touches the apple by his foot, apple is destroyed and player gets 1 point. Still OK.
What is wrong: If more players join the game, it looks like every player can see his own (local) apple. So if Player1 picks up an apple, apple is destroyed - but only for him :( all other players can see that apple still there and they can pick it up too. If I test-run the game with 2 players, in the server-window I can see that apple still there, even after all players picked it up. So the server has it's own instance apparently.
But I want just one global apple.
Application is like this:
I have an apple in the Workspace. Every few seconds I clone it in the script (not local script, but Script) which is under the AppleTree model in Workspace:
function GrowNewApple()
local newApplePos = GetRandomPlace()
local appleTemplate = workspace.apples.prototype
local newApple = appleTemplate:Clone()
newApple.Parent = appleTemplate.Parent
newApple.Name = "apple"
newApple.Position = newApplePos
end
In StarterPlayer / StarterPlayerScripts I have a localscript with this:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
character:WaitForChild("LeftFoot")
character.LeftFoot.Touched:Connect( PickUpApple )
And finally my PickUpApple function looks like this:
function PickUpApple( touchObject )
if touchObject:IsDescendantOf(workspace.apples) then
touchObject:Destroy()
end
end
Any ideas please?
Is it because the PickUpApple()
is called from LocalScript? Is it possible that this LocalScript is sending local touchObject
into this function?
I have no idea how to do this. Thanks guys.