I’m still fairly beginner to Lua scripting, but I have a question. I modelled, rigged and animated a chicken, but I want an egg to spawn near it on the same spot every 1 minute. The player can pick it up with proximity prompt, and it adds it to leaderstat as “egg”
local clone = egg:Clone() --clones the egg
clone.Parent = workspace --sets the parent to workspace
clone.Position = position -- sets the clone agg position
Delete that function entirely as it deletes the proximity prompt after 10 seconds. If you want to delete the egg after 10 seconds, change it to newEgg:Destroy().
My only assumption is interference with other scripts. There’s nothing in that script that would delete the proximity prompt, unless your changes haven’t been saved.
There’s nothing interfering. I think I just need a better script, probably. I want the egg to spawn behind the chicken and pile the eggs up by three max.
Egg = game.ServerStorage.Egg
proximityprompt = Egg.ProximityPrompt
eggsspawned = 0
studsbehindchicken = 2
max_eggs = 3 -- please keep lower than (or equal to) 9 :)
while wait(10) do
if eggsspawned < max_eggs then
local newEgg = Egg:Clone()
local c = script.Parent.CFrame
eggsspawned += 1
-- there's a better way of doing this but oh well
newEgg.CFrame = c* (CFrame.Angles(0, math.rad((7+eggsspawned)*360 / 9), 0)) * CFrame.new(0, 0, studsbehindchicken)
newEgg.Parent = workspace
if (not newEgg:FindFirstChild('ProximityPrompt')) then
local px = Instance.new('ProximityPrompt')
px.Parent = newEgg
end
newEgg.ProximityPrompt.Triggered:Connect(function(plyr)
if plyr and plyr:FindFirstChild('leaderstats') and plyr.leaderstats:FindFirstChild('Eggs') then
plyr.leaderstats.Eggs.Value += 1
end
eggsspawned-=1
newEgg:Destroy()
end)
end
end
One in one of the tree random positions. The chicken can only have up to three eggs and then it stops spawning until the rest are picked up by the player