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 3 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

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

Log in to vote
0
Answered by
DemGame 271 Moderation Voter
3 years ago
Edited 3 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:

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

0
Thank You! PurpleSouley1234 43 — 3y
Ad

Answer this question