Touch part doesn't make a TextLabel visible

Hey everyone! Second time posting on the DevForum here.
(I’m a fairly new scripter)
So I’m working on a game, and I created a Part. When you touch this part, it increases your speed x2, for a random amount of time, (between 7-15 seconds). Then it goes away and your speed returns to normal.
That works perfectly fine.
But what I want is for it to display a text on the screen that says “x2 Speed Boost!”. But it doesn’t work. I’m not getting an error message for it either.
image
The text label is set to Visible = false in the properties (which Is what I want)
image
This is the part that makes it do that (which it works)
image
And here is my script:

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	if humanoid then
		humanoid.WalkSpeed = 32
		game.StarterGui.Frame.Boosters.SpeedBoost.Visible = true
		print("Speed Boost Active")
		wait(math.random(7, 15))
		humanoid.WalkSpeed = 16
		game.StarterGui.Frame.Boosters.SpeedBoost.Visible = false
		print("Speed Boost Unactive")
		
	end
end)

Thank you.

EDIT:
This game is a one player game, so I’m using just a regular script.

Hey, you are calling for startergui on the server, with a script. You should use the players PlayerGui, or do it in a Localscript.

1 Like

Hey, this game is just a 1 player game though, so does it matter?

Yeah, unfortunately, the Server doesn’t know it’s a one player game, so it can’t act as a LocalScript. Try using Player.PlayerGui.Boosters.Frame.SpeedBoost

So I changed it back to a regular script, and now I did what you said but it doesnt seem to work.

Ah, I see. “PlayerGui” is meant to be used in a Script, not a LocalScript. If you want to use a localscript, you can use Startergui like in the script you did previously. Instead, in a script, you have to use playerGui. Also, when I say Player, I mean the “hit.Parent” that is the actual player.

If you don’t understand anything, I’d be happy to help. GUI was my nightmare when I first learnt roblox studio ;).

1 Like

id keep it as a server script and make it fire a RemoteEvent to access the players gui

You can actually get the player from hit.Parent by using Players:GetPlayerFromCharacter()

In this example:

local Model = hit.Parent
if Model:IsA("Model") and Model:FindFirstChild("Humanoid") then
     local plr = game.Players:GetPlayerFromCharacter(Model)
end
1 Like

i solved your problem, here is the script:

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if humanoid and plr then
		humanoid.WalkSpeed = 32
		plr.PlayerGui.Frame.Boosters.SpeedBoost.Visible = true
		print("Speed Boost Active")
		wait(math.random(7, 15))
		humanoid.WalkSpeed = 16
		plr.PlayerGui.Frame.Boosters.SpeedBoost.Visible = false
		print("Speed Boost Unactive")

	end
end)

The problem is you cant change anything in “startergui” with scripts, instead you can do player.PlayerGui

1 Like

I just tried it out, and it seems that the speed boost works, but the GUI still doesn’t show up

Can you explain more on that please?

1 Like

just copy mine and check if its working or not

1 Like

so the script would look like this:

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	if humanoid then
		humanoid.WalkSpeed = 32
		game.ReplicatedStorage.GuiEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent), true)
		print("Speed Boost Active")
		wait(math.random(7, 15))
		humanoid.WalkSpeed = 16
		game.ReplicatedStorage.GuiEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent), false)
		print("Speed Boost Unactive")
		
	end
end)

add a remoteevent called GuiEvent in replicatedstorage, and then put this local script into replicatedfirst (or startergui can work too, i dont remember all the places where localscripts work)

local plr = game.Players.LocalPlayer

game:GetService("ReplicatedStorage"):WaitForChild("GuiEvent").OnClientEvent:Connect(function(onOrOff)
        plr.PlayerGui.Frame.Boosters.SpeedBoost.Visible = onOrOff
end)

if i didnt miss anything then this should work, but im not sure since i just wrote it on the spot here so let me know if it gives you an error

1 Like

no need for all of that, i already solved it with the shortest way and the easiest way

1 Like

ah fine. still worth knowing how to use remotes since they can be damn useful in similar situations and theyre kinda simple

1 Like

u can not edit a players gui from a server script, which is what the thread owner is using

1 Like

you can just make the whole gui enabled or disabled using server scripts, i already done a script like that today

you can do what teef did, or just make another gui for the speed boost thing only

Do you want to enable a player guy from server right ?
If yes do this:

local part = script.Parent

part.Touched:Connect(function(hit)
local player = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent)
if player then
player.PlayerGui.prova.Enabled = true
end
end)