Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I fix my points rewarder when you collect a burger?

I made a burger and when you touch it ONCE, it disappears and rewards you 50 points. After it respawns and you collect it, it doesn't reward any points after that. Is there any way to fix this?

Reward Script

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Name = hit.Parent.Name
		local Plr = game.Players:FindFirstChild(Name)
		Plr.leaderstats.Points.Value = Plr.leaderstats.Points.Value + 50
	end
end)

Timed Regen Script

local burger = script.Parent

local backup = burger:Clone()

burger.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then -- if the part that touched it has a humanoid then
        burger:remove()
        wait(5)
        burger = backup 
        burger.Parent = game.Workspace
        burger:makeJoints()
    end
end)

2 comments

0

well, the event is only firing when the original burger is touched, not any of the clones

0

how would I make it so that the event will fire if you touch the clones?

1 answer

Moving and copying scripts can cause unexpected behaviour. It is best to put the burger and the model in a folder or model together and having something like:

burger = script.Parent.Burger
backup = burger:Clone()

local prepBurger -- required for respawnBurger not to error since prepBurger is defined below it

function respawnBurger()
  burger = backup:Clone()
  burger.Parent = game.Workspace
  prepBurger()
end

function prepBurger()
  burger.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then -- if the part that touched it has a humanoid then
        burger:Destroy()
        local Name = hit.Parent.Name
        local Plr = game.Players:FindFirstChild(Name)
        Plr.leaderstats.Points.Value = Plr.leaderstats.Points.Value + 50
        wait(5)
        respawnBurger()
    end
  end)
end

prepBurger()

This discussion is preserved as it was. New answers, comments, and votes are closed.