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

How do I replicate a tool from client to server?

Asked by 4 years ago

The problem here is that every time I run this script and open a tool from inventory it doesn't show the tool to any other clients or the server, Also the script is located in StarterCharacterScripts

01local plrs = game:GetService("Players")
02local plr = plrs.LocalPlayer
03local chr = plr.Character
04local hum = chr:WaitForChild("Humanoid")
05local leaderstats = plr.leaderstats
06local animation = Instance.new("Animation")
07animation.AnimationId = "rbxassetid://5747311876"
08local animationTrack = hum:LoadAnimation(animation)
09local cooldown = 2
10local ready = true
11local RS = game:GetService("ReplicatedStorage")
12local AddStrength = RS:WaitForChild("AddStrength")
13local tool = game.ReplicatedStorage["Strength+1"]:Clone()
14tool.Parent = plr.Backpack
15 
View all 29 lines...

1 answer

Log in to vote
0
Answered by
DemGame 271 Moderation Voter
4 years ago
Edited 4 years ago

Instead of using a local script, try using a normal script inside of StarterPlayerScripts. To use this effectively, you may have to define the player using different methods, as you cannot use Players.LocalPlayer.

How I do this is that I would search for the player using the script's parent's name.

Here is an edited piece of code:

01local plrs = game:GetService("Players")
02local plr = plrs:FindFirstChild(script.Parent.Name)
03local chr = plr.Character
04local hum = chr:WaitForChild("Humanoid")
05local leaderstats = plr.leaderstats
06local animation = Instance.new("Animation")
07animation.AnimationId = "rbxassetid://5747311876"
08local animationTrack = hum:LoadAnimation(animation)
09local cooldown = 2
10local ready = true
11local RS = game:GetService("ReplicatedStorage")
12local AddStrength = RS:WaitForChild("AddStrength")
13local tool = game.ReplicatedStorage["Strength+1"]:Clone()
14tool.Parent = plr.Backpack
15 
View all 29 lines...

Put this script in a NORMAL SCRIPT inside of StarterCharacterScripts, NOT A LOCAL SCRIPT

0
Thank You! PurpleSouley1234 43 — 4y
Ad

Answer this question