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

The tool won't go to the players backpack when cloned?

Asked by 4 years ago

This script has it so that when you click a button, a part from serverstorage clones itself and should move the clone to the players inventory/backpack. But to doesn't.

local button = workspace.mailorjobpart.ClickDetector
local door = workspace.Door
local greenpart = door.SelectionBox
local letter = game.ReplicatedStorage.letter
local letterclone = letter:Clone()

button.MouseClick:Connect(function(onclicked)
    letterclone.Parent = game.Players.LocalPlayer:FindFirstChild("Backpack")
end)
0
Any errors? compUcomp 417 — 4y
0
None show up, it just won't work unless I have to play it via actual roblox BabyHades_2 40 — 4y

3 answers

Log in to vote
2
Answered by
zomspi 541 Moderation Voter
4 years ago
Edited 4 years ago

Use replicated storage, why?

Replicated Storage Local scripts and scripts can access it Server Storage Only server scripts can access it, use this for storing maps etc

Also i suggest using a server script to move it into the players backpack, otherwise it may cause glitches and won't show up for everyone. Use a remote event so that you can still press the button.

0
So where should I store the part? And which side should I fire the remote event from, script or localscript?\ BabyHades_2 40 — 4y
0
Store the part in replicated storage, fire an event when the player clicks the GUI button, so a local script a.k.a from the client zomspi 541 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You are using a LocalScript, which can cause problems. Remember: Anything done in a LocalScript will only show on the client side. In order to make the letter appear for everyone, you should clone the object and move it to the player's backpack in a ServerScript. You can use RemoteEvents for this (look those up if you don't know what those are).

Log in to vote
0
Answered by 4 years ago

The whole operation can infact be done from the server side, as a clickdetecter being clicked ( as shown as the initiation of the giving in the initial script above ), can infact be detected by a server-side script.

From your script, I can see you have used LocalPlayer, which is part of a local script. A local script is not the correct type of script you should be using in this context, and I'll explain why. A local script's effect is purely seen on the side of the client it's executed inside of. This means that neither the server nor any other player knows of what happens in this script, meaning in this case, only the player that clicked the clickdetector would "know" of the cloned tool. A server-script, however, is automatically broadcasted to all clients, and therefore is able to achieve the effect I believe you are trying to achieve.

Here is the script I used in my test:

tool = script.TestTool
clickdetector = workspace.TestPart.ClickDetector

clickdetector.MouseClick:Connect(function(plr)
    local clone = tool:Clone()
    clone.Parent = plr.Backpack
end)

Put this in ServerScriptService, and place your tool inside of the script.To adapt, just change the routes of the variable tool, and the clickdetector.

Hope this helped.

Answer this question