#instance.new touched

6 messages · Page 1 of 1 (latest)

stuck iron
#

so i have a fully working script for now which infinitely spawns cubes with randomisation, but thats not the issue, the issue is i want to make the cubes collectable when you walk into them. but so far nothing i've tried worked.

here is what i have right now for it:

newCube.Touched:Connect(function(touched)
            local humanoid = touched.Parent:WaitForChild("Humanoid")
                if humanoid then
            game.Players.LocalPlayer.leaderstats.money = game.Players.LocalPlayer.leaderstats.money + value
        end
    end)```
the main issue in output is in the 2nd line, which when the part is touched it says 'Infinite yield possible on 'Workspace:WaitForChild("Humanoid")'
pliant narwhal
#

Hey, you need to use :FindFirstChild("Humanoid") instead of WaitForChild. That's not your biggest issue though - you can't give stats to the player on the client (LocalScript) which I assume you're doing as you're using LocalPlayer to get the player. To get the player on the server, you can do game.Players:GetPlayerFromCharacter(touched.Parent), if touched.Parent has the humanoid

#

Sorry for the pretty incoherent response, I'm on mobile but hopefully this helps

stuck iron
#

im using a regular script in serverscriptservice

#

i could send the whole script if that would help

dim briarBOT
#

studio** You are now Level 2! **studio