Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I replicate a tool from client to server?

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

local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local chr = plr.Character
local hum = chr:WaitForChild("Humanoid")
local leaderstats = plr.leaderstats
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://5747311876"
local animationTrack = hum:LoadAnimation(animation)
local cooldown = 2
local ready = true
local RS = game:GetService("ReplicatedStorage")
local AddStrength = RS:WaitForChild("AddStrength")
local tool = game.ReplicatedStorage["Strength+1"]:Clone()
tool.Parent = plr.Backpack




tool.Activated:Connect(function()
	if ready == true then
	animationTrack:Play()
	animationTrack.Looped = true
	ready = false
	wait(cooldown)
	animationTrack.Looped = false
	AddStrength:FireServer(leaderstats)
	ready = true
	end
end)


1 answer

✓ Accepted answer

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:

local plrs = game:GetService("Players")
local plr = plrs:FindFirstChild(script.Parent.Name)
local chr = plr.Character
local hum = chr:WaitForChild("Humanoid")
local leaderstats = plr.leaderstats
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://5747311876"
local animationTrack = hum:LoadAnimation(animation)
local cooldown = 2
local ready = true
local RS = game:GetService("ReplicatedStorage")
local AddStrength = RS:WaitForChild("AddStrength")
local tool = game.ReplicatedStorage["Strength+1"]:Clone()
tool.Parent = plr.Backpack




tool.Activated:Connect(function()
    if ready == true then
    animationTrack:Play()
    animationTrack.Looped = true
    ready = false
    wait(cooldown)
    animationTrack.Looped = false
    AddStrength:FireServer(leaderstats)
    ready = true
    end
end)


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

1 comment

0

Thank You!

This discussion is preserved as it was. New answers, comments, and votes are closed.