Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This isn't working in a LocalScript or a normal Script, help?

Asked by 6 years ago

So basically I'm trying to make it so when a player touches a brick it gives them a box..

This is what I have

function onTouch(hit)
if 6 > 2 then
game.Lighting["Box"]:Clone().Parent = game.Players.LocalPlayer.Backpack
wait(15)
end
end
script.Parent.Touched:connect(onTouch)

It only works in test mode and doesn't work in game... I've tried script and local script.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

From what I see here it wouldn't ever work in a normal script this way. It calls a LocalPlayer.Backpack which is impossible to call in a normal script.

Your function checks if 6 is bigger than 2 <-- ??, and then assigns the box:Clone() a parent to the local backpack.

From what I can see you want the box to go inside the player's backpack once he hits a certain item.

This is what I recommend:

game.Players.PlayerAdded:connect(function(player)

        script.Parent.Touched:connect(onTouch)

        function onTouch(hit)
            if 6 > 2 then
                local box = game.Lighting["Box"]:Clone()
                box.Parent = player.Backpack
            end
        end
end)
0
I tried that and I got a blue underline saying "consider changing it to local" for line 3 ExtremeNyanCat123 32 — 6y
0
That is no real issue, it's an error but does not mean the script doesn't work. Consider changing it to local means the variable is only being used once in an enclosed function. ROBLOX simply uses this to tell you you might aswell change the variable to a local variable. User#20989 0 — 6y
Ad

Answer this question