Okay guys, I'm making a game and i have a clickable unioned pickaxe, but it requires a server-script to run, but a local-script to add the tool to the player's backpack, The tool is in game.Lighting so it can clone it and add it to the user backpack, please help! --My Code-- ServerScript (game.Workspace.Union.Script)
script.Parent.ClickDetector.MouseHoverEnter:connect(function() script.Parent.SelectionBox.Transparency = 0.5 end) script.Parent.ClickDetector.MouseHoverLeave:connect(function() script.Parent.SelectionBox.Transparency = 1 end) script.Parent.ClickDetector.MouseClick:connect(function() --I cannot get the LocalPlayer or anything like that within a server script, which is where i am stuck end)
LocalScript (game.StarterPack)
pickaxeClicked = game.Workspace.GlobalVars.picaxeclicked while pickaxeClicked == false do --to keep the code running until pickaxe gets clicked (maybe --thats where i failed? idk) if pickaxeClicked == true then pickaxeTool = game.Lighting.Pickaxe:Clone() pickaxeTool.Parent = game.Players.LocalPlayer.Backpack end wait(0.11) end
So its pretty much just simple code.. but i cant figure out how to get the whole thing to work. Please help.
Your code is unnecessarily complicated, you can just use the serverscript. You don't need the localscript.
MouseClick GIVES you the player who clicked, so you can use that to clone.
The below code should work just fine.
script.Parent.ClickDetector.MouseHoverEnter:connect(function() script.Parent.SelectionBox.Transparency = 0.5 end) script.Parent.ClickDetector.MouseHoverLeave:connect(function() script.Parent.SelectionBox.Transparency = 1 end) script.Parent.ClickDetector.MouseClick:connect(function(playerWhoClicked) pickaxeTool = game.Lighting.Pickaxe:Clone() pickaxeTool.Parent = playerWhoClicked.Backpack end)
Alternatively, if you REALLY need to have a localscript run, you can clone it into the players character/backpack/playerGUI like this
script.Parent.ClickDetector.MouseClick:connect(function(player) someLocalScript = game.Workspace.LocalScript -- This is some sort of useful script, stored wherever, disabled. Local. clonedLocalScript = someLocalScript:clone() clonedLocalScript.Parent = player.BackPack clonedLocalScript.Disabled = false -- So it runs. end)