it worked before i added the script that would clone the tool, now it isn't working, any ideas?
local gui = script.Parent.Parent.Parent local money = game.ReplicatedStorage.Money local itemToClone = game.ServerStorage.Spaghetti local player = game.Players.LocalPlayer local button = script.Parent script.Parent.MouseButton1Click:Connect(function() if money.Value >= 50 then local clonedItem = itemToClone:Clone() clonedItem.Parent = player.Backpack money.Value -= 50 script.Click:Play() end end)
This could be the issue:Play()
is suppose to play a sound unless if you are wanting it to play a sound then that is not the issue.
Hope this helps!!
I assume you're using a local script that is a descendant of StarterGui
. Place the "Spaghetti" tool from ServerStorage
to ReplicatedStorage
because the Client (where local scripts run) cannot access ServerStorage
because judging from its name, it can only be accessed by the Server. The Server is the game itself, and only normal scripts can run in the Server-side.
The reason why you place it in ReplicatedStorage
is because it can be accessed both the Server and the Client.
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local gui = script.Parent.Parent.Parent local money = ReplicatedStorage:WaitForChild("Money") local itemToClone = ReplicatedStorage:WaitForChild("Spaghetti") -- i assume you already moved the tool in ReplicatedStorage local player = Players.LocalPlayer local button = script.Parent button.MouseButton1Click:Connect(function() if money.Value >= 50 then local clonedItem = itemToClone:Clone() clonedItem.Parent = player.Backpack money.Value -= 50 script.Click:Play() end end)
But this still isn't the final asnwer..
I recommend using RemoteEvent
s because this script can be an advantage for hackers by changing the Money
value in their client, so create a RemoteEvent
inside ReplicatedStorage
and name it CloneTool, and make a normal script inside ServerScriptService
Your local script in the button should look like this:
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local gui = script.Parent.Parent.Parent local removeEvent = ReplicatedStorage:WaitForChild("CloneTool") -- i assume you already created a RemoteEvent inside ReplicatedStorage and named it "CloneTool" local player = Players.LocalPlayer local button = script.Parent local clickSound = script.Click button.MouseButton1Click:Connect(function() task.spawn(clickSound.Play, clickSound) -- plays the sound remoteEvent:FireServer() end)
And your normal script in ServerScriptService
:
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local removeEvent = ReplicatedStorage.CloneTool -- i assume you already created a RemoteEvent inside ReplicatedStorage and named it "CloneTool" local itemToClone = ReplicatedStorage.Spaghetti -- i assume you already moved the tool in ReplicatedStorage local money = ReplicatedStorage.Money remoteEvent.OnServerEvent:Connect(function(player) if money.Value >= 50 then local clonedItem = itemToClone:Clone() clonedItem.Parent = player.Backpack money.Value -= 50 end end)
BUT THIS STILL ISN'T THE FINAL ANSWER!!
I recommend placing the Money
value to each player instead because it can be changed by any player (and even the Server) if it's in ReplicatedStorage
. So if you have any scripts that use ReplicatedStorage.Money
YOU BETTER CHANGE THEM!
Final normal script in ServerScriptService
:
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local removeEvent = ReplicatedStorage.CloneTool -- i assume you already created a RemoteEvent inside ReplicatedStorage and named it "CloneTool" local itemToClone = ReplicatedStorage.Spaghetti -- i assume you already moved the tool in ReplicatedStorage Players.PlayerAdded:Connect(function(player) local money = Instance.new("IntValue", player) money.Name = "Money" end) remoteEvent.OnServerEvent:Connect(function(player) if player.Money.Value >= 50 then local clonedItem = itemToClone:Clone() clonedItem.Parent = player.Backpack player.Money.Value -= 50 end end)
sorry for long answer :P
local Players = game:GetService("Players") local gui = script.Parent.Parent.Parent local money = game.ReplicatedStorage:WaitForChild("Money") local itemToClone = game.ServerStorage:WaitForChild("Spaghetti") local button = script.Parent button.MouseButton1Click:Connect(function(plr) if money.Value >= 50 then local clonedItem = itemToClone:Clone() clonedItem.Parent = plr.Backpack money.Value -= 50 script.Click:Play() end end)
for T3_MasterGamer
local Players = game:GetService("Players").LocalPlayer local money = Players.Money local multiplier = game.ReplicatedStorage.Multiplier debounce = false script.Parent.Touched:connect(function(hit) if not debounce then debounce = true if(hit.Parent:FindFirstChild("Humanoid")~=nil)then script.Parent:Destroy() money.Value += 1 * multiplier.Value end debounce = false end end)