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

This press on item for gear script wont work?

Asked by
Vid_eo 126
8 years ago

I'm making it so that when you press on an item, a gear is in a player's hand. It won't work, though, and there's nothing in the output.


SCRIPT:

Player = game.Players.LocalPlayer
TableProp = script.Parent
RageTable = game.ReplicatedStorage:WaitForChild("RageTable")

function RageTableEquipped()
    local a = RageTable:Clone()
    a.Parent = Player.Backpack  
    local b = RageTable:Clone()
    b.Parent = Player.StarterGear
end
TableProp.ClickDetector.MouseClick:connect(RageTableEquipped)

The rage table is the gear, and the script is in "CoffeeTableProp"

Thanks

--club101coolguy

0
It needs to be a LocalScript to work TheDeadlyPanther 2460 — 8y
0
It is Vid_eo 126 — 8y

1 answer

Log in to vote
0
Answered by
Legojoker 345 Moderation Voter
8 years ago

This is a very common error made in the early stages of scripting. The reason that your script doesn't work is because LocalScripts do not run if they aren't some sort of descendant of either the player's character, or player instance (such as in GUIs or BackPack). To fix this, make the script a Server Script and change the way Player is accessed. Here is what I did to tackle the problem:

function rageTable()
    return game.ReplicatedStorage:WaitForChild("RageTable"):Clone()
end

script.Parent:WaitForChild("ClickDetector").MouseClick:connect(function(player)
    rageTable().Parent = player.Backpack
    rageTable().Parent = player.StarterGear
end)

Because the argument that is given to the listening event MouseClick for ClickDetectors is the player who clicked the brick, this allows us easy access to the userdata we need. This way, the use of LocalPlayer (which only works in local scripts) isn't necessary.

0
ServerStorage or ServerScriptService? Vid_eo 126 — 8y
0
Nvm, it was in coffee table. Thx! Vid_eo 126 — 8y
Ad

Answer this question