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

Simple coin collecting script not working. help?

coins get teleport ed into the work space but i have trouble making them dissapear and add 1 dollar to my GUI


script.Parent.Touched:Connect(function(hit)
		game.Players.LocalPlayer.PlayerGui.CollectionCoinRocketGui.Frame.TextBox.iValue.Value = game.Players.LocalPlayer.PlayerGui.CollectionCoinRocketGui.Frame.TextBox.iValue.Value + 1
	    script.Parent:Destroy()
	
end)

1 answer

If this script is a LocalScript, it's a mistake. If this script is a Script, i'ts okay. But you don't can use game.Player.LocalPlayer whith the server, because the server is not a client.

To make it, you do need used RemoteEvent.

ServerScript:

local Debounce = true

script.Parent.Touched:Connect(function(hit)
	local Player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
	if Player and Debounce then
		Debounce = false
		game:GetService('ReplicatedStorage').RemoteEvent:FireClient(Player)
		script.Parent:Destroy()
	end
end)

LocalScript:

local Player = game:GetService('Players').LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')
local CollectionCoin = PlayerGui:WaitForChild('CollectionCoinRocketGui')

game:GetService('ReplicatedStorage').RemoteEvent.OnClientEvent:Connect(function()
	CollectionCoin.Frame.TextBox.iValue.Value = CollectionCoin.Frame.TextBox.iValue.Value + 1
	CollectionCoin.Frame.TextBox.Text = CollectionCoin.Frame.TextBox.Text
end)

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