Tool doesn't work when it is in Repllicated storage

Hello, I was putting a tool in the replicated storage, and giving it to players if they own a gamepass for the tool, but when I put the tool in the ReplicatedStorage, the tool does not play the “Slash” animation, and it does not do any damage. When I put the tool in the StarterPack, the tool works fine.

This is the script for the tool, this is a script inside the tool (I followed Tech with Mike’s YouTube tutorial on how to make a tool.):

local tool = script.Parent
local canDamage = false

local function onTouch(otherPart)
	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
	if not humanoid then
		return
	end

	if humanoid.Parent ~= tool.Parent and canDamage then
		humanoid:TakeDamage(25)
	else
		return
	end

	canDamage = false
end

local function slash()
	local stringValue = Instance.new("StringValue")
	stringValue.Name = "toolanim"
	stringValue.Value = "Slash"
	stringValue.Parent = tool
	canDamage = true
end

tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

Also this is the script for giving the tool when they have the gamepass (I followed @Eppobot’s tutorial on how to make a gamepass):

local player = game.Players.LocalPlayer
local playerOwnsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237750)

if playerOwnsGamepass then
	local frozenStick = game:GetService("ReplicatedStorage"):WaitForChild("FrozenStick"):Clone()
	frozenStick.Parent = player.Backpack
end

Is there a solution to fix this? Thank you.

Try putting the tool inside of Lighting and changing the code to respect this change.

1 Like

I have a question (I’m not saying I am doubting you): Why do I put the tool inside the Lighting?

Scripts don’t run inside of ReplicatedStorage, not sure if this is shared between ReplicatedStorage and Lighting but it’s just something you could try. See if it works!

To change your code to work with Lighting simply change ReplicatedStorage to Lighting.

1 Like

It still doesn’t work even if I put the tools inside Lighting.

It still doesn’t work… :frowning_face:

How did you test whether or not the tool works?

I tested the tools in Roblox Studio.

Using the start local server feature? Did you manually give yourself the tools and try to damage or did you spawn with it and try to damage another test player?

Could you link me the game and test it on me? I see no reason for it to not work.

1 Like

One question, is this necessary or what is it for? You say that the Slash animation does not play, but I don’t see where it is.

And you should do this script as one of the server and move the tool to ServerStorage

game.Players.PlayerAdded:Connect(function(player)
	local Success, Has = pcall(function()
		return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237750)
	end)

	if Success and Has then
		local frozenStick = game:GetService("ServerStorage"):WaitForChild("FrozenStick"):Clone()
		frozenStick.Parent = player.Backpack
	end
end)
1 Like

That’s a default Roblox animation I think. Some weird hardcoded stuff.

I think the value of the Slash animation is in the StringValue where is says

stringValue.Value = "Slash"

Tool article provides this insight:

But as requested before please provide me with a game link so you can test the tool on me, I don’t think you tested it correctly.

1 Like

Since the tool isn’t doing the animation, the tool doesn’t do a damage too.
When I played the game with my friends, the tool didn’t do any damage to other players.

Here is the video:
robloxapp-20210629-1307376.wmv (1.1 MB)

Also, I can test with you right now in a server.
Here is the game link:
https://www.roblox.com/games/6962214049/Penguin-Run

wow, why have I never seen that before?

if you put the script like this, does it print something?

local tool = script.Parent
local canDamage = false

print("im here")

local function onTouch(otherPart)
    print(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
    if not humanoid then        return            end
    
    if humanoid.Parent ~= tool.Parent and canDamage then
        humanoid:TakeDamage(25)
    end
    canDamage = false
end

local function slash()
    local stringValue = Instance.new("StringValue")
    stringValue.Name = "toolanim"
    stringValue.Value = "Slash"
    stringValue.Parent = tool
    canDamage = true
end

print("Connect")
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

Is the following code a LocalScript or a Script? And where is this script located?

local player = game.Players.LocalPlayer
local playerOwnsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 19237750)

if playerOwnsGamepass then
	local frozenStick = game:GetService("ReplicatedStorage"):WaitForChild("FrozenStick"):Clone()
	frozenStick.Parent = player.Backpack
end
1 Like

That script is in a LocalScript, located inside StarterGui.

Ah!
Change that to a Script inside of ServerScriptService.

And give @SOTR654 the solution as they mentioned this before.

1 Like

Now it doesn’t give the tool when I put a script inside a ServerScriptService.