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”
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
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)
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.
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.
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)
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.
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.
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