Why does this script not work

in this script sometimes u just freeze ( supposed to happen ) but no gui happens, and the ending text which becomes visible, doesnt show:

local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
	local player = Players:FindFirstChild(hit.Parent.Name)
	if player:FindFirstChild("ShouldPlayEnding").Value == true then
		player:FindFirstChild("ShouldPlayEnding").Value = false
		player:FindFirstChild("Ending").Value = "Car Crash"
		game.ReplicatedStorage.freezeeverything:FireAllClients()
		game.ReplicatedStorage.disablereset:FireAllClients()
		wait(1)
		game:GetService("BadgeService"):AwardBadge(player.UserId, 2992784962412130)
		local playerGui = player:FindFirstChild("PlayerGui")
		if playerGui then
			local endGui = playerGui:FindFirstChild("EndingFoundText")
			if endGui then
				endGui.Enabled = true
				endGui.EndingText.Text = "your ending: " .. player:FindFirstChild("Ending").Value
				endGui.ImageLabel:TweenPosition(UDim2.new(-1.994, 0, -1.994, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.5, true)
				endGui.ImageLabel:TweenSize(UDim2.new(4.862, 0, 4.988, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.5, true)
				task.wait(1.5)
				endGui.EndingText.Visible = true
			end
		end
	end
end)

Why are you defining the playergui in a server script? I’m assuming it’s a server script because you are using FireAllClients with the remote event from ReplicatedStorage, if you want to define the PlayerGui then it needs to be in a client script (local script)

Go through the basics, man :sob:

Learn more about remote events here

u can use playergui in a server script, i also did this with another part touch and the ending text shows for that, its the exact same script as that except the text is different like here its Car Crash, for the other its Drown

never in my ~3 years of scripting experience have i been told that you can manipulate playergui on the server

1 Like

Me neither, I remember not being able to realise whats wrong because no errors are printing out when I tried to run it over playergui :sweat_smile:

Are you sure though? Because I ran some tests right now and I am definitely able to control it.

From the looks of it it should be working fine. Maybe your screengui is disabled? Is something up with your values? You could print stuff out throughout to script to check which parts of it are even working in the first place.
I copied your script but removed the parts where it checked values and tweened the imagelabel to not have to recreate your entire system. It worked well for me.

This should work as long as you have everything like the Guis setup correctly, I also shortened and cleaned up the code a bit for you for readability-sake :slight_smile:

local BadgeService = game:GetService("BadgeService")
local PlayerService = game:GetService("Players")

script.Parent.Touched:Connect(function(otherPart)
	if otherPart.Parent:FindFirstChild("HumanoidRootPart") then
		local character = otherPart.Parent
		local player = PlayerService:GetPlayerFromCharacter(character)
		
		-- do all your value changing stuff here (although it will be inside of the character and NOT the player which i reccommend)
		
		BadgeService:AwardBadge(player.UserId, 2992784962412130)
		
		local playerGui = player:FindFirstChild("PlayerGui")
		if playerGui then
			local endGui = playerGui:WaitForChild("EndingFoundText") -- make sure EndingFoundText is a ScreenGui, of course
			local ending = player:FindFirstChild("Ending").Value
			
			endGui.Enabled = true
			endGui.EndingText.Text = "your ending: " .. ending
			endGui.ImageLabel:TweenSizeAndPosition(UDim2.fromScale(4.862, 0, 4.988), UDim2.fromScale(-1.994, -1.994), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.5)
			task.wait(1.5)
			endGui.EndingText.Visible = true
		end
	end
end)

:exclamation:Recommended

think of firing a RemoteEvent to the Player to handle their GUI rather than fetching PlayerGui on the Server and doing all the Tweens here too… just for optimization

1 Like

you shouldn’t run tweens/animations on the server because it will not be smooth on the client and will increase the internet recv

ye this works thx i edited it to what i need

so i shouldnt run on server bcuz it wont be smooth on client? doesnt make sense

well now u have been told u can

What he means by this is, when firing Tweens or handling almost any kind of movement (player, GUI, objects, VFX and much more… you should handle it on the Client (the players device) rather than running it on the ROBLOX Servers as this will cause lag, FPS drops and an unpleasant and overall delayed experience… You used Remotes in your original script to “FreezeEverything” and “DisableReset” which is a good start but as I said, fire a Remote to the Player who got the ending and then receive that through a Local Script and run all the GUI Tweens on that Script :sunglasses:

1 Like

you shouldn’t run animations or tweens on the server
for example, if you tween a part CFrame on the server the server will send the CFrame 60 times every second and it will be delayed depending on the clients PING which will make it not look smooth also it will increase the incoming network

What Is Ping? (Gaming)
Roblox Devs: We Need to Talk
Optimizing Tweens - Roblox Scripting Tutorial

This is the most hilarious post I’ve ever seen from OP :sob::sob::sob:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.