Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Tan0ak 28
4 years ago

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)
1
You would need to clone the tool to the player's backpack on the server and not the client (LocalScript). uhi_o 417 — 4y
1
can u show me what that would look like Tan0ak 28 — 4y

1 answer

Log in to vote
1
Answered by
uhi_o 417 Moderation Voter
4 years ago

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.

Ad

Answer this question