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.
local coin = game.Workspace.Coin
local remote = game.ReplicatedStorage.CoinEvent
remote.OnServerEvent:Connect(function(player)
coin:Destroy()
remote:FireClient(player, "changeValue")
end)
-- a space between 2 scripts
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!
5 comments
why is this all on 2 lines
is this a server script?
no, its in the coin
thats not what i asked
Did you get this from google? Otherwise, I would recommend learning lua syntax because this is very wrong.