Script doesn't work

I’ve made a script which gives an item to a player if he buys it. The thing is everything works with ProximityPrompt but not for the Textbutton. If i click the textbutton then it wont give me the “item”.

This is the script i used.

And this is the path
path

can somebody please explain what i did wrong?

As we can see here TextButton | Roblox Creator Documentation. The TextButton doesn’t say who pressed the button or there’s no (function(player) just (function(), So it won’t really work. I never tried using SurfaceUi button function but i think this would work.

• Create a localscript in StarterPlayerScript
• then write your function there

 (Path to button).MouseButton1Click:Connect(function()

end)
2 Likes

So i’ve fixed it. Thanks for helping me out btw.
This is the code:

player = game.Players.PlayerAdded:Wait()
game.Workspace.Woodenmenuboard.Menu.SurfaceGui.Frame.teabt.MouseButton1Click:Connect(function()
	if player.leaderstats.cash.Value > 4 then 
		player.leaderstats.cash.Value -= 4 

		local Tool = game.ServerStorage.ToolsFolder["tea"]:Clone()
		Tool.Parent = player.Backpack
	end
end)
1 Like

I think you should use game.Players.PlayerAdded:Connect(function(player) instead of player = game.Players.PlayerAdded:Wait() because it will stop waiting if a player joined or it only works for a single user or the first person to play. Np too!

1 Like

Now it works even better! Thanks buddy!

1 Like