Remote events not working

Hello, im trying to change a string value in replicated storage, and its simply not working, its to change whenever the character seats on a specific seat or leaves, but it dont change.

local script:

local players = game.Players

local localPlayer = players.LocalPlayer

local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()

local humanoid = character:WaitForChild("Humanoid")

local replicatedStorage = game:GetService("ReplicatedStorage")

for _, missions in pairs(replicatedStorage.Missions:GetChildren()) do

local event = missions.ChangeState

local state = missions.Values.State

local vehicle = missions.Values.Vehicle.Value

event:FireServer(humanoid, vehicle, state)

end

server script

local replicatedStorage = game:GetService("ReplicatedStorage")

local event = replicatedStorage.Missions.HouseDrive.ChangeState

local function changeText(humanoid, vehicle, state)
	if vehicle.Occupant == humanoid then
		state.Value = "InVehicle"
	elseif vehicle.Occupant == nil then
		state.Value = "EnterVehicle"
	end
end
1 Like

You’re not binding changeText to the event - add another line at the end of the server script and bind changeText to the event with the Connect function.

Wow, that was such an oversight, now its saying that occupant is not part of humanoid but i specified that vehicle is the seat, and sorry im new to remote events and i dont know how to use this additional information

The first argument of onServerEvent is the player who fired it, so change this:

local function changeText(humanoid, vehicle, state)
	if vehicle.Occupant == humanoid then
		state.Value = "InVehicle"
	elseif vehicle.Occupant == nil then
		state.Value = "EnterVehicle"
	end
end

to this:

local function changeText(player, humanoid, vehicle, state)
	if vehicle.Occupant == humanoid then
		state.Value = "InVehicle"
	elseif vehicle.Occupant == nil then
		state.Value = "EnterVehicle"
	end
end
1 Like

i tried that before, it didnt work, the script is now this:

local:

local players = game.Players

local localPlayer = players.LocalPlayer

local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()

local humanoid = character:WaitForChild("Humanoid")

local replicatedStorage = game:GetService("ReplicatedStorage")

for _, missions in pairs(replicatedStorage.Missions:GetChildren()) do

local event = missions.ChangeState

event:FireServer()

end

server:

local replicatedStorage = game:GetService("ReplicatedStorage")

for _, missions in pairs(replicatedStorage.Missions:GetChildren()) do
	local event = missions.ChangeState
	local state = missions.Values.State
	local vehicle = missions.Values.Vehicle.Value

	event.OnServerEvent:Connect(function(player)
		if vehicle.Occupant == player.Character.Humanoid then
			state.Value = "InVehicle"
		elseif vehicle.Occupant == nil then
			state.Value = "EnterVehicle"
		end
	end)
end

i forgot to put the seat in the objectvalue Lol

Now no errors but the value is not changing, why is it so hard???

any solutions? it shouldnt be that hard

You didn’t connect the function to the remote event so the changeText function would not be ran

i already did that? look up

30

Oh, apologies then I didn’t see that

Also, why is the OnServerEvent in a for loop? Try putting it outside the the for loop.

its because im trying to make a mission system and i thought it would be easier to add more missions eventually using mission.name if statement

but i dont see any really difference putting it off, and i wouldnt be able to get the variables i think

I’m pretty sure the code is iterating through all the items in the “Missions” so perhaps try this:

local replicatedStorage = game:GetService("ReplicatedStorage")`

for _, missions in pairs(replicatedStorage.Missions:GetChildren()) do
	local event = missions.ChangeState
	local state = missions.Values.State
	local vehicle = missions.Values.Vehicle.Value

	spawn(function()
		event.OnServerEvent:Connect(function(player)
			if vehicle.Occupant == player.Character.Humanoid then
				state.Value = "InVehicle"
			elseif vehicle.Occupant == nil then
				state.Value = "EnterVehicle"
			end
		end)
	end)
end

Edit:I didn’t test it so I’m not sure if it works