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

If-Statement not proceeding when all expressions are true?

Asked by 4 years ago
Edited 4 years ago

Simple as the title, the If-Statement is not proceeding when all the expressions are true. I'm trying to see if the player is sitting and the parent of the seat that the player is sitting in is called "Bed". Not sure why it is not firing.

More info: Already made sure that the model of the seat is actually "Bed" (using print), and the if statement does fire when the player is seated (Without the 2nd expression), it's just when I added the second expression, it's not firing.

More Details: The script is in a LocalScript in StarterGui, just tried using game.Players.LocalPlayer.Character with no luck. Also, this is just a snippet of the actual code, I do have an average knowledge of lua, so there aren't any basic errors (like missing an end). Updated script below.

if game.Players.LocalPlayer.Character.Humanoid.Sit == true and game.Players.LocalPlayer.Character.SeatPart.Parent.Name == "Bed" then
        game.Workspace.Values.NumInBed.Value = workspace.Values.NumInBed.Value + 1
        script.Parent.Parent.Character.Humanoid.JumpPower = 0
0
Use this to get the character. \\-- game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() --// All of that to get the character. killerbrenden 1537 — 4y
0
Just tried before you commented, didn't work. I'll make a note. DevMonty 12 — 4y
0
You're also missing an end at the bottom to close off the function. killerbrenden 1537 — 4y
0
This is not the full code, just a snippet of it.... DevMonty 12 — 4y
0
Oh ok killerbrenden 1537 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I'm not 100% sure what you're trying to do. I also recommend to not change values on the client side, try the server side using RemoteEvents, ServerScripts, and LocalScripts.

But, I think this is somewhat of what you're trying to do?

local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local ws = game:GetService("Workspace")

if humanoid.Sit == true and humanoid.SeatPart.Parent.Name == "Bed" then
    ws.Values.NumInBed.Value = ws.Values.NumInBed.Value + 1
    humanoid.JumpPower = 0
end
0
Looks great. It's still not working! I've gotta set up a basic simulation using the script to see if it's something else (which it probably is). Thank you very much for helping! I really appreciate it! DevMonty 12 — 4y
0
No problem! Glad to help! killerbrenden 1537 — 4y
Ad

Answer this question