Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The error says that playergui isn't a valid member?

Help, I tried making a script that breaks the enemies leg but when it ends up picking the number then the script says that PlayerGui isn't a valid member of Player

function legbreak()
local legbreak = math.random(1, 3)
if legbreak == 1 then
local chr = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(chr)
print(plr.Name)
wait(RoF)
plr.PlayerGui.GUI.Data.legbroken.Value = true
hit.Humanoid.WalkSpeed = 10
plr.PlayerGui.GUI.HUD.BrokenLeg.Visible = true
print("Yes")
elseif legbreak == 2 then
print("No")
elseif legbreak == 3 then
print("No")
end
end

3 comments

1

You never made this a Touched event.

0

You never defined hit in the script. Therefor you should not be getting a character, and that should return nil on the plr variable.

0

That's not the full script. I'm using a gun script but this is the only part that doesn't work now stop saying I don't have a hit -_-

1 answer

A few errors:

function legbreak(hit) -- Needs to know what hit is. I declared it here.
local legbreak = math.random(1, 3)
if legbreak == 1 then
local chr = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(chr)
print(plr.Name)
wait(RoF)
plr.PlayerGui.GUI.Data.legbroken.Value = true
hit.Humanoid.WalkSpeed = 10
plr.PlayerGui.GUI.HUD.BrokenLeg.Visible = true
print("Yes")
elseif legbreak == 2 then
print("No")
elseif legbreak == 3 then
print("No")
end
end
script.Parent.Touched:connect(legbreak) -- Calls the function.

The rest looks about right :) Hope I helped.

1 comment

0

No it's already a hit, it's a raycast script. I'm not posting the full thing -_-

This discussion is preserved as it was. New answers, comments, and votes are closed.