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

I'm trying to give the player the tool if they click on a part but i dosen't work?

Asked by 5 years ago
Edited 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

If the player clicks the tool then i'm cloning it to the serverstorage and destoying the tool that the player clicked on. And then it will look like you picked it up. but it dosen't work, Help would be appreciated.

Inside Local script:

local Clone = game.ReplicatedStorage:FindFirstChild("BlueBerry1"):Clone()

local Playerbackpack = game.Players.LocalPlayer.Backpack

local Click = workspace.BlueBerry1.Part.ClickDetector

local Bill = workspace.BlueBerry1.Part.BillboardGui

-----------------------------------------------------------

Click.MouseClick:Connect(function()

game.ReplicatedStorage.BlueBerry1:Clone()

wait()

Clone.Parent = Playerbackpack

wait(0,5)

end)
0
Babyseal : you can't use "Workspace" that won't work, that is deprecated. Freddan2006YT 88 — 5y
0
Oh did I get it backwards? I just use game.Workspace. Babyseal1015 56 — 5y
0
You use workspace becuase it's faster and better Freddan2006YT 88 — 5y
0
No. It is not. game.Workspace or game:GetService("Workspace") is consistent since there is no built in `players` variable for example to get Players User#24403 69 — 5y
0
You have to say game.Workspace because Workspace is a child of the game, just like ReplicatedStorage is a child of them game. You can't just say workspace otherwise the script won't know where to look. JayShepherdMD 147 — 5y

1 answer

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

Ok, so first things first, you can't do this in a local script. A local script is client sided, meaning that it can only control things involving the player, so yes in a local script you can call game.Players.Localplayer.Backpack with ease a local script can't control a click detector like ClickDetector.MouseClick. So instead we use a regular script and the way we get in touch with the player is within the function:

local clicker = script.Parent.ClickDetector
clicker.MouseClick:Connect(function(player)

When we say function(player) this player in the brackets is now the player that clicked this detector, so with this we can finish the script.

Script

 local RepStorage = game:GetService("ReplicatedStorage")

 local clicker = script.Parent.ClickDetector



clicker.MouseClick:Connect(function(player)

 local backpack = player:FindFirstChild("Backpack")

 local Clone = RepStorage.ClassicSword

 Clone.Parent = backpack

 wait(0.5)

 end)

Also you cloned the item twice in your script once out side of the function and once in the function.

And then finally when you want to get ReplicatedStorage the best method is to use: local replicatedStorage = game:GetService("ReplicatedStorage")

If you have any questions please let me know

0
Also I forgot to mention this is a script inside of the part you want people to click. Babyseal1015 56 — 5y
0
Why do you need FindFirstChild("Backpack") isn't it obvios the player has a backpack? Freddan2006YT 88 — 5y
0
You do that so you don't cause any errors. If you just say player.backback there is a chance that it can cause an error, it's the same reason why if you want to do something with a humanoid in a server script you would say player:FindFirstChild('Humanoid') we would only say FindFirstChild("backpack") in a server script, if it were a local script you could just say player.backpack. Babyseal1015 56 — 5y
0
We also do it because it's a server script dealing with a client sided object, you need to be careful dealing with the client in a server script. Babyseal1015 56 — 5y
Ad

Answer this question