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

If-Statement not proceeding when all expressions are true?

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

5 comments

0

Use this to get the character. \-- game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() --// All of that to get the character.

0

Just tried before you commented, didn't work. I'll make a note.

0

You're also missing an end at the bottom to close off the function.

0

This is not the full code, just a snippet of it....

0

Oh ok

1 answer

✓ Accepted answer

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

2 comments

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!

0

No problem! Glad to help!

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