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

How can I make it so when you sit in a seat, if your username does not match a value, it jumps you?

I am trying to make a booking system, and I am trying to make it so if you sit in a seat, and your username does not match the true owner of the seat (which the username of the true owner is in a string value), then it will jump you. I have tried with many attempts, but I have not succeeded. How do you go about this? My scripts are below. I have both the local script and standard script as a child of the seat.

-- Local Script
local Username = script.Parent.Parent:WaitForChild("Username")
local UsernameValue = Username.Value
script.Parent.ChildAdded:Connect(function()
	if script.Parent.Occupant.Parent.Name == UsernameValue then
		local donothing = game
	else
		script.Parent.KickOutOfSeat:FireServer()
	end
end)

-- Normal Script
script.Parent.KickOutOfSeat.OnServerEvent:Connect(function()
		script.Parent.SeatWeld:Destroy()
		script.Parent.SeatWeld:Destroy()
		script.Parent.SeatWeld:Destroy()
		script.Parent.SeatWeld:Destroy()
		script.Parent.SeatWeld:Destroy()
		script.Parent.SeatWeld:Destroy()
		script.Parent.SeatWeld:Destroy()
		script.Parent.SeatWeld:Destroy()
end)

2 comments

0

This won't work ever is the problem, you simply can't use a localscript this way.

2

Also why do you hate the seat weld so much?

2 answers

Firstly, LocalScripts do not run in the Workspace unless they are descendant of a player's character, which is in the Workspace. They also run as descendants of the Backpack, PlayerGui, PlayerScripts, and ReplicatedFirst. Secondly, you do not need a remote event for this at all. You can listen for the Occupant property changing, with the :GetPropertyChangedSignal() method.

local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then -- if the occupant is there
		seat.Occupant.Jump = true
	end
end)

Finally, you do not need to call :Destroy() on an object 7 times. Once will suffice.


######Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.

--Local script

script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
	local Username = script.Parent.Parent:WaitForChild("Username")
	if script.Parent.Occupant ~= Username.Value then
		script.Parent.KickOutOfSeat:FireServer()
	end
end)


--Server Script
script.Parent.KickOutOfSeat.OnServerEvent:Connect(function(plr)
	plr.Character.Humanoid.Jump = true
end)

I'd like to note that I can already tell that you're going to have problems running this. As the code implies, both the server script and the local script are children of the same remote event. You should know that local scripts cannot run in workspace, which is where I'm assuming it's located.

3 comments

0

If you know not logic you will know that line 5 will fail.

0

should be > if script.Parent.Occupant ~= Username.Value then

0

was accident, was typing fast

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