coins get teleported 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)
We're going to define some of your scripting objects with variables to make this look cleaner and take less scripting space.
local playergui = game.Players.LocalPlayer.PlayerGui local textbox = playergui.CollectionCoinRocketGui.Frame.TextBox script.Parent.Touched:Connect(function(hit) textbox.iValue = textbox.iValue + 1 script.Parent:Destroy() end)
Unfortunately, this wouldn't work. ROBLOX has made it so you have to use Filtering Enabled, meaning you have to use RemoteEvents
. But RemoteEvents are somewhat easy to learn, don't stress.
So we're going to be using a ServerEvent instead of a ClientEvent for this procedure.
ServerEvent's Fire from the Server, whilst ClientEvent's Fire from the Client.
So we'll need 2
scripts, instead of 1
. We'll also need an Event, we'll call it, hmm.
CoinEvent, as it is related to our Coin situation and Events. Hence, CoinEvent.
We'll place this CoinEvent into ReplicatedStorage.
-- ServerScript local coin = game.Workspace.Coin -- Change this to whatever your coin is called local remote = game.ReplicatedStorage.CoinEvent -- Defining the CoinEvent remote.OnServerEvent:Connect(function(player) -- Everything in this function will run when called/fired/triggered coin:Destroy() remote:FireClient(player, "changeValue") end)
-- a space between 2 scripts
--ClientLocalScript local remote = game.ReplicatedStorage.CoinEvent game.Workspace.Coin.Touched:Connect(function() remote:FireServer() end) remote.OnClientEvent:Connect(function(changeValue) if changeValue == "changeValue" then local playergui = game.Players.LocalPlayer.PlayerGui local textbox = playergui.CollectionCoinRocketGui.Frame.TextBox local value = textbox.value.Value textbox.TextLabel.Text = value + 1 end end)
I changed the Value to TextLabel since it works the same way and Value isn't working for some reason. I don't know if it's because I didn't know if your Value is a Value or something else, I tested this out and it works fine. But read the --'s as they will help you modify it along the way. If this helped, click the big Accept Answer button at the bottom of this text. Thanks!