Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Simple coin collecting script not working. help?

Asked by 5 years ago

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)
0
why is this all on 2 lines DinozCreates 1070 — 5y
0
is this a server script? DinozCreates 1070 — 5y
0
no, its in the coin natonator63 29 — 5y
0
thats not what i asked DinozCreates 1070 — 5y
0
Did you get this from google? Otherwise, I would recommend learning lua syntax because this is very wrong. SteamG00B 1633 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

0
Thanks! i'm better with remote event's now. natonator63 29 — 5y
0
Your welcome. TheOnlySmarts 233 — 5y
Ad

Answer this question