My GUI is broken because when i load up a game w/ my brother I will click Shop to open the shop but the GUI then opens on his screen, and then we cannot close it. Here is the script i use...
dUKey = "PlayerDamageUpgrades" hUKey = "PlayerHealthUpgrades" sUKey = "PlayerSpeedUpgrades" game.Players.PlayerAdded:connect(function(player) if player:WaitForDataReady() then u = Instance.new("IntValue") u.Name = "upgrades" u.Parent = player dU = Instance.new("IntValue") dU.Name = "DamageUpgrades" dU.Parent = u dU.Value = player:LoadNumber(dUKey) hU = Instance.new("IntValue") hU.Name = "HealthUpgrades" hU.Parent = u hU.Value = player:LoadNumber(hUKey) sU = Instance.new("IntValue") sU.Name = "SpeedUpgrades" sU.Parent = u sU.Value = player:LoadNumber(sUKey) end end) game.Players.PlayerRemoving:connect(function(player) if player:FindFirstChild("upgrades") then player:SaveNumber(dUKey, player.leaderstats.dU.Value) player:SaveNumber(hUKey, player.leaderstats.hU.Value) player:SaveNumber(sUKey, player.leaderstats.sU.Value) end end) name = "Dmg Upgrade 1" cost = 1 -- the price. currencytype = "StatPoints" -- this is the value in the leaderboard the weapon is paid with. game.Players.PlayerAdded:connect(function(nP) -- Connect event to anonymous funtion nP.CharacterAdded:connect(function(nC) sG = Instance.new("ScreenGui", nP.PlayerGui) sG.Name = "ShopGui" fr = Instance.new("Frame", sG) fr.Position = UDim2.new(0,0,.5,-15) fr.Size = UDim2.new(0,150,0,60) fr.Style = "ChatBlue" tb = Instance.new("TextButton", fr) tb.Size = UDim2.new(1,0,1,0) tb.Style = "RobloxButtonDefault" tb.TextColor3 = Color3.new(1,1,1) tb.Text = "Shop" tb.MouseButton1Click:connect(function() tb.Transparency = 1 cl = Instance.new("TextButton", fr) cl.ZIndex = 2 cl.Size = UDim2.new(1,0,1,0) fr.Style = "ChatRed" cl.TextColor3 = Color3.new(1,1,1) cl.Text = "Close" cl.Style = "RobloxButtonDefault" cl.MouseButton1Click:connect(function() cl:Remove() frdUB:Remove() tb.Transparency = 0 fr.Style = "ChatBlue" end) frdUB = Instance.new("Frame", sG) frdUB.Name = "DMGUpgradeFrame" frdUB.Position = UDim2.new(0,150,.5,-60) frdUB.Size = UDim2.new(0,150,0,60) frdUB.Style = "ChatGreen" dUB = Instance.new("TextButton", frdUB) dUB.Size = UDim2.new(1,0,.5,0) dUB.Style = "RobloxButtonDefault" dUB.TextColor3 = Color3.new(1,1,1) dUB.Text = "Upgrade Damage by 5" cdU = Instance.new("TextLabel", frdUB) cdU.Position = UDim2.new(0,0,.5,0) cdU.Size = UDim2.new(1,0,.5,0) cdU.BackgroundColor3 = Color3.new(1,1,1) cdU.Text = "Cost: 1 Skill Point" dUB.MouseButton1Click:connect(function() dUB:Remove() cdU:Remove() y = Instance.new("TextButton", frdUB) y.Size = UDim2.new(.5,0,.5,0) y.Position = UDim2.new(0,0,.5,2) y.TextColor3 = Color3.new (0,1,0) y.Text = "Yes" y.Style = "RobloxButtonDefault" n = Instance.new("TextButton", frdUB) n.Size = UDim2.new(.5,0,.5,0) n.Position = UDim2.new(.5,0,.5,2) n.TextColor3 = Color3.new (1,0,0) n.Style = "RobloxButtonDefault" n.Text = "No" rS = Instance.new("TextLabel", frdUB) rS.Size = UDim2.new(1,0,.5,0) rS.BackgroundColor3 = Color3.new(0,0,0) rS.TextColor3 = Color3.new(1,1,1) rS.Text = "Are you sure?" y.MouseButton1Down:connect(function() s = script.Parent local l = s:FindFirstChild("leaderstats") if l then local m = l:FindFirstChild(currencytype) if m then if m.Value >= cost then m.Value = m.Value - cost local pS = Instance.new("ScreenGui", s.PlayerGui) pS.Name = "Purchase Successful" pSF = Instance.new("Frame", pS) pSF.Position = UDim2.new(0,0,.3,0) pSF.Size = UDim2.new(0,150,0,30) pSF.Style = "RobloxRound" pSF.BackgroundColor3 = Color3.new(0,1,0) pST = Instance.new("TextLabel", pSF) pST.Position = UDim2.new(1,0,1,0) pST.Size = UDim2.new(1,0,1,0) pST.TextColor3 = Color3.new(0,0,1) pST.Text = "You just purchased "..name.." for "..cost.." StatPoint!" elseif m.Value < cost then local pF = Instance.new("ScreenGui", s.PlayerGui) pF.Name = "Purchase Failed" pFF = Instance.new("Frame", pF) pFF.Position = UDim2.new(0,0,.3,0) pFF.Size = UDim2.new(0,150,0,30) pFF.Style = "RobloxRound" pFF.BackgroundColor3 = Color3.new(1,0,0) pFT = Instance.new("TextLabel", pFF) pFT.Position = UDim2.new(1,0,1,0) pFT.Size = UDim2.new(1,0,1,0) pFT.TextColor3 = Color3.new(0,0,1) pFT.Text = "ERROR: You do not have enough StatPoints for that!" end end end y:Remove() n:Remove() rS:Remove() dUB = Instance.new("TextButton", frdUB) dUB.Size = UDim2.new(1,0,.5,0) dUB.Style = "RobloxButtonDefault" dUB.TextColor3 = Color3.new(1,1,1) dUB.Text = "Upgrade Damage by 5" cdU = Instance.new("TextLabel", frdUB) cdU.Position = UDim2.new(0,0,.5,0) cdU.Size = UDim2.new(1,0,.5,0) cdU.BackgroundColor3 = Color3.new(1,1,1) cdU.Text = "Cost: 1 Skill Point" wait(2) pF:Remove() end) end) end) end) end)
Thanks for the help but with your fix could you please tell me why it happened, what happened, how to prevent it in the future, and basically anything important that will help me become a better scripter because I REALLY REALLY want to master this. Thanks again mates :)!