I think it has something to do with the remote event.
The server event script for the tool:
local liftSwordEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("LiftSword") liftSwordEvent.OnServerEvent:Connect(function(player,cashIncreaseValue) local cash = game.Players[script.Parent.Parent.Name].leaderstats.Cash for i, toolsInCharacter in pairs(script.Parent.Parent:GetChildren()) do if toolsInCharacter and toolsInCharacter:IsA("Tool") then local cashIncrease = toolsInCharacter:WaitForChild("CashIncrease") local multiplier = toolsInCharacter:WaitForChild("CashMultiplier") if multiplier then cash.Value = cash.Value + cashIncrease.Value * multiplier.Value end end end end)
The local script for the tool:
local sword = script.Parent local liftSwordEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("LiftSword") sword.Activated:Connect(function() if sword.Parent == game.Players.LocalPlayer.Character then liftSwordEvent:FireServer() end end)
The leaderstats script
game.Players.PlayerAdded:Connect(function(player) local folder = Instance.new("Folder",player) folder.Name = "leaderstats" local cash = Instance.new("IntValue",folder) cash.Name = "Cash" cash.Value = 1500 local weaponsOwned = Instance.new("Folder",player) weaponsOwned.Name = "weaponsowned" local sword1owned = Instance.new("BoolValue",weaponsOwned) sword1owned.Name = "Sword1owned" sword1owned.Value = false local sword2owned = Instance.new("BoolValue",weaponsOwned) sword2owned.Name = "Sword2owned" sword2owned.Value = false end)
Thanks!
Not sure what is up, tbh I never even looked. But you can simplify this code. First up why is there a for loop? Just to check if there is a tool equipped? Use :FindFirstChildOfClass
here.
Also you do not need :WaitForChild
since the objects will be loaded in already.
local liftSwordEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("LiftSword") liftSwordEvent.OnServerEvent:Connect(function(player) local cash = player.leaderstats.Cash local tool = player.Character:FindFirstChildOfClass("Tool") if tool then local cashIncrease = tool.CashIncrease local multiplier = tool.CashMultiplier cash.Value = cash.Value + cashIncrease.Value*multiplier.Value end end)
And for your Activated
listener... why test if they have the tool equipped when Activated
ONLY fires if the tool is even equipped? How can you activate it without it even being equipped?
sword.Activated:Connect(function() liftSwordEvent:FireServer() end)