Basically I’m trying to make a plane, that, when sat in, creates a remote event named after the user who sat in it (I don’t know how else to prevent the user from controlling multiple planes on accident, so if someone helps me with that it would nullify the issue I’m having now.). The problem is, even though the remote event is placed in ReplicatedStorage, the server is never able to see it.
Server Script
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
print("Detected change in seat.")
if(seat.Occupant ~= nil) then -- When the player sits in the vehicle:
print("copying local script now")
local newls = ls:Clone()
--print(controls)
newls.Parent = seat.Occupant.Parent --the local script being copied contains code to create the remote event.
print("waiting on remote event now!")
wait(2)
controls = storage:WaitForChild(seat.Occupant.Parent.Name,20)
print(controls)
Local Script
local storage = game:GetService("ReplicatedStorage")
local plr = game:GetService("Players").LocalPlayer
local controls = Instance.new("RemoteEvent") --storage:WaitForChild("controls")
controls.Name = plr.Name
controls.Parent = storage
print("created remote event!")
Anything made with a Local Script or on the Client the Server is unable to see.
I am not understanding the issue, because the seat has the Occupant property which allows you to see who is in it. (The Property has the Character’s Humanoid)
I am just confused on how the Player would be able to control multiple planes?
If they were in a different plane the Occupant would be nil or another player for the last one.
I just have to go back through my code, not sure how but when i get in one plane, it controls two at the same time. I don’t know why I didn’t really consider the occupant property… been looking at the code for too long. Thanks
game.Players.PlayerAdded:Connect(function(player)
local event = Instance.new('RemoteEvent', game.ReplicatedStorage)
event.Name = tostring(player.Name..'SeatedEvent')
end
game.Players.PlayerRemoving:Connect(function(player)
game.ReplicatedStorage:FindFirstChild(player.Name..'SeatedEvent'):Destroy()
end