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

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

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)

1 comment

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.

1 answer

✓ Accepted answer

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!

2 comments

0

Thank you!

0

Glad I helped!

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