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

How do I check if player is Sit==true or PlatformStand==true? [ANSWERED]

I have the code below which simply teleports the Player to a location if the Value within the model is == to the Player's name - Tycoon like owner. And if the Player isn't the owner then a GUI is show to him.

I would also like the script to check if the Player isn't seating because I have vehicles in the game, and being teleported with the vehicle would mess the game up, and I can't seem to figure it out..

The script without my attempt at checking if the player is seated:

function onTouch(part) 
	local plr = game.Players:GetPlayerFromCharacter(part.Parent) 
	local Character = plr.Character or plr.CharacterAdded:wait()
	local Torso = Character:WaitForChild("Torso")
	local enabled = false
	
	if (plr ~= nil) then
		if not enabled then
			if plr.Name == script.Parent.Parent.OwnerName.Value then
			
		Torso.CFrame = CFrame.new(-640.875, -84.657, -339.195)
		
enabled = true

	else
		plr.PlayerGui.NotTheOwner.Frame.Visible = true
		
enabled = false
		
			end 
		end
	end 
end

script.Parent.Touched:connect(onTouch)


--[[
Output:
Script:4: attempt to index local 'plr' (a nil value)

Even though there is an output for this, the script WORKS properly
--]]


The script once more, but with my attempt (NOT WORKING)

function onTouch(part) 
	local plr = game.Players:GetPlayerFromCharacter(part.Parent) 
	local Character = plr.Character or plr.CharacterAdded:wait()
	local Torso = Character:WaitForChild("Torso")
	local enabled = false
	
	if (plr ~= nil) then
		if not enabled then
			if plr.Name == script.Parent.Parent.OwnerName.Value then
			
		Torso.CFrame = CFrame.new(-640.875, -84.657, -339.195)
		
enabled = true
				elseif plr.Name == script.Parent.Parent.OwnerName.Value and 
				if Character.Humanoid.Sit == true or Character.Humanoid.PlatfromStand == true then
				plr.PlayerGui.IsSeated.Frame.Visible = true

	else
		plr.PlayerGui.NotTheOwner.Frame.Visible = true
		
enabled = false
				end
			end 
		end
	end 
end

script.Parent.Touched:connect(onTouch)

3 answers

✓ Accepted answer

I cannot test it properly without the gui ect . This should work but let me know if there are any errors.

function onTouch(part) 
	local plr = game.Players:GetPlayerFromCharacter(part.Parent) 
	local Wplr = part.Parent	
	local humanoid = Wplr:FindFirstChild("Humanoid")	
    local enabled = false
	
    if Wplr ~= nil and humanoid ~= nil then
		print(1)
		if not enabled then
			
			--Check player name and if sitting then makes player stand		
			if Wplr.Name == script.Parent.Parent.OwnerName.Value and  not humanoid.sit then
				
				Wplr.Torso.CFrame = CFrame.new(-640.875, -84.657, -339.195)
				enabled = true
				
			elseif Wplr.Name == script.Parent.Parent.OwnerName.Value then --player owns the base but is sitting
				
				plr.PlayerGui.IsSeated.Frame.Visible = true
				
			else
							
				plr.PlayerGui.NotTheOwner.Frame.Visible = true --player not owner	
				
				enabled = false --dont know why you need this?
			end
    	end 
	end
end
script.Parent.Touched:connect(onTouch)

8 comments

0

When I'm not the owner and I touch the Part, I get: attempt to index local 'plr' (a nil value)

0

This might work, change line 2 :- local plr = game.Players:FindFirstChild (part.Parent)

0

The same error

0

Where is the player gui? I managed to get it working, i put a gui in th starterpack and it worked using the code above

0

The Gui is simply a StarterGui which goes into > game.Players.Player.PlayerGui

0

Oh, thank you! This one works :) I'd +1 you,but people on here have put my points down to -9 - haha :)

0

just mark the thread as answered :)

The humanoid located in a Player's Character has 3 proprieties of use to you

Jump

Sit

PlatformStand

These are all bool values.

If the player is sitting, Sit is true. Same with PlatformStand

You can check these values to see if the player is sitting or not.

Likewise, setting Jump to true will cause the player to jump, and is true when they are jumping.

A simple solution to your problem would be to cause the player to jump before you attempt to move them.

I would go through workspace finding all seats and connecting a event to Seated that triggers a function to fire a event that says who sat down and what seat so baisicly this


function GetSeats(v,tab)
	local Seats
	if tab==nil then
	Seats={}
	else
	Seats=tab
	end
	for _,part in next,v:GetChildren() do
		if part:IsA("Seat") then
			table.insert(Seats,part)
		elseif part:GetChildren()~=nil then
			GetSeats(part,Seats)
		end
	end
	return Seats
end
local Seat=GetSeats(game.Workspace,nil)
for _,s in next,Seat do
	s.Touched:connect(function(p)
		if p.Parent:FindFirstChild("Humanoid")~=nil then
		local plyr=game.Players:GetPlayerFromCharacter(p.Parent) or nil
		if plyr~=nil then
			print(plyr.Name.."has seated")
		end
		end
	end)
end

2 comments

0

So, how do I use it relating to my code?

0

Please rep me if you like it

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