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

Why isn't my PlayerGui working as intended?

Asked by 4 years ago
Edited 4 years ago

So I wrote this script that allows a player to find/collect special coins, and when they do, the coins become semi-transparent, signifying to the player collecting that they already collected this coin and they cannot collect it again. It then adds the found coin to a coin count in a gui at the bottom left corner (It allows them to go from 1/7, 2/7...7/7 kind of like in slender when you need to collect all 7 pages). I have it set under the PlayerGui, however, everyone's gui changes with the person who collects the coins. Instead, I'd like everyone's Coin count in the gui to remain at 0 and the coins to remain opaque until the players collect the coins themselves.

Also, once a player resets, the coins collected remain transparent for all players, but the coin counter resets and goes back to 0, which is not acceptable.

  • the script is in StarterGui but it is being called in PlayerGui
  • the coins are meshes in the workspace

If anyone knows my problem and knows how to fix it, please do explain. Thank you.

local coinTrack1 = true
local coinTrack2 = true
local coinTrack3 = true
local coinTrack4 = true
local coinTrack5 = true
local coinTrack6 = true
local coinTrack7 = true
local coinNum = 0

player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin1.Touched:Connect(function(hit)
    if coinTrack1 == true then
        if hit.Parent:WaitForChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            coinNum = coinNum + 1
            player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
            game.Workspace.RedCoin1.Transparency = .7

            coinTrack1 = false
            return coinNum


        end
    end

end)
game.Workspace.RedCoin2.Touched:Connect(function(hit)
    if coinTrack2 == true then
        if hit.Parent:WaitForChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            coinNum = coinNum + 1
            player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
            game.Workspace.RedCoin2.Transparency = .7

            coinTrack2 = false
            return coinNum


        end
    end

end)
game.Workspace.RedCoin3.Touched:Connect(function(hit)
    if coinTrack3 == true then
        if hit.Parent:WaitForChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            coinNum = coinNum + 1
            player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
            game.Workspace.RedCoin3.Transparency = .7

            coinTrack3 = false
            return coinNum


        end
    end

end)
game.Workspace.RedCoin4.Touched:Connect(function(hit)
    if coinTrack4 == true then
        if hit.Parent:WaitForChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            coinNum = coinNum + 1
            player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
            game.Workspace.RedCoin4.Transparency = .7

            coinTrack4 = false
            return coinNum


        end
    end

end)
game.Workspace.RedCoin5.Touched:Connect(function(hit)
    if coinTrack5 == true then
        if hit.Parent:WaitForChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            coinNum = coinNum + 1
            player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
            game.Workspace.RedCoin5.Transparency = .7

            coinTrack5 = false
            return coinNum


        end
    end

end)
game.Workspace.RedCoin6.Touched:Connect(function(hit)
    if coinTrack6 == true then
        if hit.Parent:WaitForChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            coinNum = coinNum + 1
            player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
            game.Workspace.RedCoin6.Transparency = .7

            coinTrack6 = false
            return coinNum


        end
    end

end)
game.Workspace.RedCoin7.Touched:Connect(function(hit)
    if coinTrack7 == true then
        if hit.Parent:WaitForChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            coinNum = coinNum + 1
            player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
            game.Workspace.RedCoin7.Transparency = .7

            coinTrack7 = false
            return coinNum


        end
    end

end)

1 answer

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

I think it's because you are detecting if someone touches the coin and making it so that it changes for everyone so instead you could get the player name that touched the coin and make it specifically so that it changes only for them. You did

local player = game.Players.LocalPlayer
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin1.Touched:Connect(function(hit)
 if coinTrack1 == true then
if hit.Parent:WaitForChild("Humanoid") then
 coinNum = coinNum + 1
player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
game.Workspace.RedCoin1.Transparency = .7
return coinNum

where as you need to take hit and get the name of the player that hit it from there and change their Gui

I might be wrong but that's all I've got

0
Good idea, but I don't think it will change the transparency problem of the coins only changing for a player who collected it BreckleShrimp 23 — 4y
0
hmm, you could make it transparent for all players using "player" but change the coin amount using hit.Parent Longjohnnn 28 — 4y
0
I'm not sure what you mean, though i am going to accept this answer because I think in order to do this I'll have to create a LocalMesh which I think is a whole other question. BreckleShrimp 23 — 4y
0
Sorry for not explaining it properly. I mean find the name of the player that touched the coin by doing hit.parent.parent then comparing it to the localPlayers name and if it is the same then change the Gui but if it is different then don't. Then for making it transparent you could detect if it has been hit and just make it transparent for everyone for example Longjohnnn 28 — 4y
View all comments (4 more)
0
Coin.touchedConnect(function(hit) Coin.Transparency = 0.7 Longjohnnn 28 — 4y
0
Also I recommend doing something like local Coin1 = game.Workspace.RedCoin1 to make the script shorter Longjohnnn 28 — 4y
0
Thank you! BreckleShrimp 23 — 4y
0
You're welcome :D Longjohnnn 28 — 4y
Ad

Answer this question