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

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

Asked by 8 years ago

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
1
You never made this a Touched event. alphawolvess 1784 — 8y
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. M39a9am3R 3210 — 8y
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 -_- ScriptingCon 52 — 8y

1 answer

Log in to vote
-2
Answered by 8 years ago

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.

0
No it's already a hit, it's a raycast script. I'm not posting the full thing -_- ScriptingCon 52 — 8y
Ad

Answer this question