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.
The text label is set to Visible = false in the properties (which Is what I want)
This is the part that makes it do that (which it works)
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.
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
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.
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
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)