I have a script here that, when block1 (box) touches block2 (incinerator), it gives the player points in each of their leaderstats and also destroys the block and triggers particles. It all works perfectly just as I want it to…except that I have it fetching the players information through PlayerAdded. The aim of the game is buying blocks and burning them. When you buy a block, it clones from ReplicatedStorage into the workspace. That makes the whole script useless because the block is being added after the player. I’ve tried to use GetPlayers instead, but my trouble there is that I don’t quite understand tables as of yet, and I’m trying to learn. Here is my code inside the block:
local fire = game.Workspace.Incinerator.FireParticle
local sound = game.Workspace.Incinerator.Explode
game.Players.PlayerAdded:Connect(function(player)
local boxes = player:WaitForChild("leaderstats").Boxes
local cash = player:WaitForChild("leaderstats").Cash
script.Parent.Touched:Connect(function(touchingPart)
if touchingPart == game.Workspace.Incinerator then
boxes.Value = boxes.Value + 1
cash.Value = cash.Value + 1
fire.Enabled = true
sound:Play()
wait(0.1)
script.Parent:Destroy()
wait(0.6)
fire.Enabled = false
end
end)
end)
(Note: this is a one player game, and I am using a normal script. I am doing this because it is easier for me as I don’t yet understand local scripts and client sided functions.)
I would greatly appreciate if someone is able to explain to me what I need to change and possibly how it works so I am able to do it on my own in the future. Thank you to anyone who helps, and if you need me to give any more details on what im doing then please ask.
Video of the already existing part working, while the exact copy part that i spawn in, doesnt work.