Saying the UI is not vaild even though it is

Trying To make a script that teleports you, opens UI and awards you leaderstats depending on if you have a gamepass or not.

So here it is.

local part = script.Parent
local deb = false
local gamepass1 = 18141166
local gamepass2 = 18141180
local marketplaceService = game:GetService('MarketplaceService')
--- Gamepass 1 is wins
--- Gamepass 2 is coins
local debtime = 1


part.Touched:Connect(function(hit)
	local touchPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
	local GUI = touchPlayer.PlayerGui.Winnerpartthing
	local teleporter = script.Parent.Parent.Parent.Lobby.InvisiblePart

	function WinningStuff(CoinsNum,WinsNum)
		hit.Parent.HumanoidRootPart.CFrame = teleporter.CFrame
		touchPlayer.leaderstats.Wins.Value += WinsNum
		touchPlayer.leaderstats.Coins.Value += CoinsNum
		GUI.Coins.MainText = "+"..CoinsNum
		GUI.Wins.MainText = "+"..WinsNum
		GUI.Coins.Visible = true
		GUI.Wins.Visible = true
		wait(4)
		GUI.Coins.Visible = false
		GUI.Wins.Visible = false
		wait(debtime)
		deb = false
	end

	if not touchPlayer or deb then return end

	deb = true
	if marketplaceService:UserOwnsGamePassAsync(touchPlayer.UserId, gamepass1) and marketplaceService:UserOwnsGamePassAsync(touchPlayer.UserId, gamepass2) then
		WinningStuff(100,2) --- Both Gamepasses
	elseif marketplaceService:UserOwnsGamePassAsync(touchPlayer.UserId, gamepass1)then
		WinningStuff(50,2) -- Just 2x Wins
	elseif marketplaceService:UserOwnsGamePassAsync(touchPlayer.UserId, gamepass2) then
		WinningStuff(100,1) -- Just x2 Coins
	else
		WinningStuff(50,1) -- No Gamepasses
	end

end)

It is giving out this error.

Show explorer

Of what?

The Gui?

Or the part?

PlayerGui when game is running

GUI.Coins.MainText.Text = "+"..CoinsNum
1 Like

Just going to say this, do not handle/change GUI on the server, it won’t work. I recommend you handle GUI on the client instead if you are doing so on the server. You can maybe handle the part touching on the server and try to get the player from there via the game.Players:GetPlayerFromCharacter function. Once you have the player, you can look for the player’s leaderstats and then change it on the SERVER. For the GUI stuff, do that on the client. Use remotes if necessary.

1 Like