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

Why won't tools show for other players but only for the person whos holding the tool?

Asked by 4 years ago
Edited by Leamir 4 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

Okay so, I was making a shop gui for my game and I made it so that when you click a button it gives you a tool for a certain amount of currency that I also added into my game. But the problem is, when you buy the tool you the person who's holding the tool can see it, but other players can't see the tool that you're holding.

I'm not sure if this is a bug or if I put something wrong in my script, but heres my script.


local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function(click) if player.leaderstats.Points.Value >= 50 then player.leaderstats.Points.Value = player.leaderstats.Points.Value - 50 game.ReplicatedStorage.Tools.Flashlight:Clone().Parent = player:WaitForChild("Backpack") end end)

I also have another tool with the same script but its a taco.

2 answers

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Thats because the tool is not being replicated to server, you need to clone it and change leaderstats value via serverscript, or it will only change for localplayer

Ad
Log in to vote
0
Answered by 4 years ago

To add on to what Leamir said, you need to do it on the server;

Add a remoteevent to ReplicatedStorage and a serverscript in the serverscriptservice,

Name the RemoteEvent whatever, let's say we name it 'RE'.

In the localscript above, you call the event, like so

local event = game:GetService("ReplicatedStorage"):WaitForChild("RE")
event:FireServer()

Then in the server script you can put

local event = game:GetService("ReplicatedStorage"):WaitForChild("RE")
event.OnServerEvent:connect(function(player) --when firing from client to server the first parameter will always be player

--Do stuff in here, clone the tool, anything you do will be replicated across the server

end)

Remember that exploiters can fire your remote event, so do your checks before executing the code on the server.

0
ohhhh okay! tysm! LostedMxnd 2 — 4y
0
wait im still very confused, how would I set everything up? I'm really new to this whole scripting stuff. LostedMxnd 2 — 4y
0
so do I add a local script to replicated storage and a regular script to serverscriptservice? LostedMxnd 2 — 4y

Answer this question