Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My freeze during intro doesn't work?

Asked by
Aepeus 59
9 years ago

I'm trying to make a script that freezes the player if the intro is still active. But humanoid is underline, and there is no signs of errors in the box.

local PlayerName = game.Players.LocalPlayer.Name

if game.Players.LocalPlayer.PlayerGui.ScreenGui.Main.Visible == true then 
    game.Workspace[""..PlayerName..""]Humanoid.WalkSpeed.Value = 0
    else game.Workspace[""..PlayerName..""]Humanoid.WalkSpeed.Value = 16
end

0
You need a . after the bracket, and there is no need for the "".. .."" M39a9am3R 3210 — 9y

2 answers

Log in to vote
0
Answered by
ItsMeKlc 235 Moderation Voter
9 years ago

On line 4/5 you don't need the parenthesis and you would need a period after it. And I would use WaitForChild. So try this:

local PlayerName = game.Players.LocalPlayer.Name

if game.Players.LocalPlayer.PlayerGui.ScreenGui.Main.Visible == true then 
    game.Workspace:WaitForChild(PlayerName).Humanoid.WalkSpeed.Value = 0
    else game.Workspace:WaitForChild(PlayerName).Humanoid.WalkSpeed.Value = 16
end

Ad
Log in to vote
0
Answered by 9 years ago

A few things here can be made more efficient, and the problem is mostly typos.

The problem is you're trying to find the player in the workspace with a string, by trying to reference it directly as though it were an object. You need to use FindFirstChild() or WaitForChild() to find an object with a string. However, these methods aren't needed here, because you can reference the character directly through the player.

local player = game.Players.LocalPlayer
local character = player.Character --The character can be referenced easily through the player

if player.PlayerGui.ScreenGui.Main.Visible == true then 
    character.Humanoid.WalkSpeed.Value = 0
    else character.Humanoid.WalkSpeed.Value = 16
end


Answer this question