Why is this happening please help

  1. What do you want to achieve? Keep it simple and clear!

I want this winner GUI to show up for all players in the game when someone touches the part “testpart”

  1. What is the issue? Include screenshots / videos if possible!

Alright so this is seriously really weird I have done everything correctly and it still doesn’t appear for the players but it appears for the SERVER with the message “The winner is Workspace” i’m extremely confused at this point

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried looking online about this problem and I tried doing this with both Remote Events and Remote Functions the only one that worked is Remote Events but it only appeared for the server not the players… and with the message “The winner is Workspace”…

I have no errors in the output plus every single print in the event listener and the local script works too and I have tried everything that is in my hands to fix this problem but i’m just seriously extremely confused at this point as to why Workspace is even the winner…

Local script inside StarterPlayerScripts
local replicatedstorage = game:GetService("ReplicatedStorage")
local remoteevent = replicatedstorage:WaitForChild("showtext1")
local touched1 = game.Workspace.parts:WaitForChild("testpart")
local winnergui = game.StarterGui.winner.TextLabel

if #game.Players:GetPlayers() >= 2 then
	touched1.Touched:Connect(function(hit)
		if game.Players:GetPlayers(hit.Parent) then
			print("the Part has been touched")
			remoteevent:FireServer(winnergui, hit)
		end
	end)
end
the event listener which is in ServerScript Service inside a script
local replicatedstorage = game:GetService("ReplicatedStorage")
local remoteevent = replicatedstorage:WaitForChild("showtext1")

remoteevent.OnServerEvent:Connect(function(player, winnergui, hit)
	print("everything good")
	winnergui.Text = "The winner is "..tostring(hit.Parent)
	winnergui.BackgroundTransparency = 0
	wait(5)
	winnergui.BackgroundTransparency = 1
	print("done")
end)

5fe64b107aa58e5fdb4aa10570de00f1

1 Like

This is the common mistake of modifying the gui in StarterGui. This does not work, because it only changes future GUI copies, not current ones. Instead, change it in a localscript that is inside the GUI. You do not need any RemoteEvents.

1 Like

I have tried doing that but it says that “PlayerGui is not a valid member of DataModel”

That error is correct. Don’t try to access game.PlayerGui. Instead, “navigate” from script. If the script is directly under the ScreenGui, use script.Parent instead of game.PlayerGui.ScreenGui.

This does not work. You meant to do game.Players:GetPlayerFromCharacter(hit.Parent)

1 Like

Oh mb yeah I meant to do that but will it even work if I do that?

Should I move the script inside the TextLabel? I think keeping it inside StarterPlayerScripts is causing no harm?

Put that in the function, or else it will check once, but it won’t check again whenever the part is touched.

I made it so the part destroys itself instantly after being touched so that shouldn’t be an issue

First of all you need to replace game.Players:GetPlayers(hit.Parent) with game.Players:GetPlayerFromCharacter(hit.Parent), as mentioned above.

Second of all, StarterGui is client-sided. Changing the text there from the server will have no effect on the players. What you need to do is make the server use FireAllClients to tell the clients to change the text in their PlayerGui, not StarterGui.

Ideally, you should parent the LocalScript to the gui in StarterGui and do something like this:

local gui = script.Parent
local winnergui = gui.TextLabel

local remote = game.ReplicatedStorage:WaitForChild("showtext1")
remote.OnClientEvent:Connect(function(winner)
    winnergui.Text = "The winner is ".. winner
    winnergui.BackgroundTransparency = 0
    wait(5)
    winnergui.BackgroundTransparency = 1
end)

and the server:

local replicatedstorage = game:GetService("ReplicatedStorage")
local remoteevent = replicatedstorage:WaitForChild("showtext1")

remoteevent.OnServerEvent:Connect(function(player, winnergui, hit)
    local winner = game.Players:GetPlayerFromCharacter(hit:FindFirstAncestorOfClass("Model"))
    if winner then
        remoteevent:FireAllClients(winner.Name)
    end
end)
3 Likes

No, you have to put it in the function or it will only check once in the beginning, Instead of checking everytime the part is touched. If there wasn’t 2 players when the script started, then the function will never run.

Do you have any idea why it said that Workspace is the winner tho?

part is touching the workspace

Because of your if game.Players:GetPlayers(hit.Parent) then, which was always true. Therefor even if the part touched any other part in workspace, it would get fired and pass the check.

Btw you might want to listen to Touched event on the server, not on the client.

But I have a code inside the script that checks if the part is touching something else other than a player so that’s impossible

Nevermind maybe it was because I said game.Players:GetPlayers() instead of game.Players:GetPlayerFromCharacter()

you checked for the hit.Parent, which was Workspace

workspace is not a BasePart. It can’t touch other things. It’s more likely that it touched the BasePlate, and printed BasePlate.Parent => Workspace

1 Like

yes, that was what I said. the parent of hit(baseplate) which was Workspace

Hey I tried your scripts that you gave me but they still didn’t work now it doesn’t even tell the server who won do you have any other solutions? there’s no errors in the output too