Coin Spawning Module and GUI enabler onTouch, how?

(this has been solved)

What I want to achieve is:
Enabling my GUI in StarterGui once a player picks up a coin/candy cane and disabling it after 1.5 seconds.

I’ve tried this:
script.Parent.OnTouch:Connect
Touch.Parent.PlayerGui.Confetti.Enabled = True
wait(1.5)
Touch.Parent.PlayerGui.Confetti.Enabled = False
Touch.Parent.leaderstats.Coins = +10
script.Parent:Remove

My problem is:

This doesn’t work and I want it into a module.

I think more logical way of calling your code should be like this:

script.Parent.Touched:Connect(function(hit)
 if hit.Parent:FindFirstChild("Humanoid") then
  game.Players:FindFirstChild(tostring(hit.Parent)).PlayerGui:FindFirstChild("Confetti").Visible = true
  wait(1.5)
  game.Players:FindFirstChild(tostring(hit.Parent)).PlayerGui:FindFirstChild("Confetti").Visible = false
  game.Players:FindFirstChild(tostring(hit.Parent)).leaderstats.Coins.Value = game.Players:FindFirstChild(tostring(hit.Parent)).leaderstats.Coins.Value + 10
  script.Parent:Destroy()
 end
end)

Also for respawning you can use module script to respawn it. This actually looked like an old style code to me. Send me code if you have it and I’ll rescript it no problem. I hope this helps. :herb:

3 Likes

I can’t mark this as a solution YET as I am away from my computer, doing homework but if it works I’ll mark it!

1 Like

Can confirm this works now! I’ve found the respawning module from a user called ‘Clashzone_FC’. Thanks!

1 Like

Is it a script or localscript btw? My guess is script but I’m confused as to the new Lua. I’ve been away from roblox for 8 years lol.

There shouldn’t be any problems calling this from script.

1 Like

please can you put the content of the post back as it can be used as future reference for other users

4 Likes

As mentioned above, please don’t edit your topic to remove the original question once you’ve found a solution. Some people may have the same issue and will benefit from being able to see how you solved it.

3 Likes

I’m sorry but I can’t get it back.

Do yourself and everyone else a favour, put the player in a variable to avoid annoying redundancy and use the proper functions to do this.

local Players = game:GetService("Players")

script.Parent.Touched:Connect(function (hit)
    local character = hit.Parent
    if character:IsA("Model") and character:FindFirstChild("Humanoid") then
        local player = Players:GetPlayerFromCharacter(character)
        if player then
            -- Guis don't have a Visible property? Shouldn't do this from the server either.
            player.PlayerGui.Confetti.Visible = true
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
            wait(1.5)
            player.PlayerGui.Confetti.Visible = false
            script.Parent:Destroy()
        end
    end
end)
2 Likes

I know that it doesn’t have a visible property. It should be an Enabled property.