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

I am making a shop GUI, but the tool give script isn't working properly. Can someone help?

Asked by 4 years ago

The script is in a text button, and there is an IntValue in the button. (for the cost) It works with local script, but won't seem to show on other players screens, or run any scripts within it. Can someone help?

player = game.Players.LocalPlayer
DP = player.leaderstats.DamagePoints
price = script.Parent.Cost.Value
tool = script.Parent:FindFirstChild("UpgradedSword")

function buy()
     if DP.Value >= price then
        DP.Value = DP.Value - price

        local a = tool:clone()

        a.Parent = player.Backpack

        local b = tool:clone()

        b.Parent = player.StarterGear

    end
end

script.Parent.MouseButton1Down:Connect(buy)
0
Local scripts only work for the client, that player the scripts are in. It won't activate any other players gui's or normal scripts. To activate a normal script, you would have to use a remote event. zandefear4 90 — 4y

1 answer

Log in to vote
0
Answered by
zomspi 541 Moderation Voter
4 years ago

I had this same issue, you need to use a remote event with a server script to do this. Add a remote event to replicatedstorage called "fire"

Local Script:

script.Parent.MouseButton1Down:Connect(function()
game.ReplicatedStorage.Fire:FireServer()

Server Script


DP = player.leaderstats.DamagePoints price = script.Parent.Cost.Value tool = script.Parent:FindFirstChild("UpgradedSword") game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player) if DP.Value >= price then DP.Value = DP.Value - price local a = tool:clone() a.Parent = player.Backpack local b = tool:clone() b.Parent = player.StarterGear end end)

If I helped please accept this answer!

0
Thank you! peytonallen920 66 — 4y
0
Glad I helped! zomspi 541 — 4y
Ad

Answer this question