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

So when i buy a tool from my shop the damage script wont run. Can someone help me?

so when i buy a tool from shop my tools damage script wont run.

my damage script:

local tool = script.Parent
local Damage = 7
local debouce = false
local Holding = false
tool.Equipped:Connect(function()
	Holding=true
end)

tool.Unequipped:Connect(function()
	Holding=false
end)

tool:WaitForChild("blade").Touched:Connect (function (hit)
	if hit.Parent:FindFirstChild("Humanoid") and debouce == false and Holding == true then
		debouce = true
		hit.Parent.Humanoid:TakeDamage(Damage)
		wait(.5)
		debouce = false
	end
	
end)

my shop script:

local player = game.Players.LocalPlayer
local Saber = game.ReplicatedStorage.Weapons["Sith Saber"]

script.Parent.MouseButton1Down:Connect(function()
	if player.leaderstats.Cash.Value >= 40 then 
		player.leaderstats.Cash.Value = player.leaderstats.Cash.value - 40
		 Saber:Clone().Parent = player:WaitForChild("Backpack")
	end
end)

2 comments

1

You would need to clone the tool to the player's backpack on the server and not the client (LocalScript).

1

can u show me what that would look like

1 answer

✓ Accepted answer

So you would need to fire a remote event and give the player the tool on the server.

Local Script

local player = game.Players.LocalPlayer
local Remote = YOUREMOTEDIRECTORY --YOURREMOTEDIRECTORY

script.Parent.MouseButton1Down:Connect(function()
    Remote:FireServer(40)
end)

Server Script

local Remote = YOUREMOTEDIRECTORY --YOURREMOTEDIRECTORY
local Saber = game.ReplicatedStorage.Weapons["Sith Saber"]

Remote.OnServerEvent:Connect(function(player, price)
    if player.leaderstats.Cash.Value >= price then
        Saber:Clone.Parent = player.Backpack
        Saber:Clone().Parent = player.StarterGear --Just so it stays when respawned
    end
end)

Also, I would suggest putting the remote in ReplicatedStorage and make sure to define it in the variables I have placed.

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