Checker for my vehicle not working?

So I have this script that detects if a cars driver seat is close to the “gas pump” so its ready to fill up, but its saying “workspace” is not a valid member of datamodel

local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()

mouse.Button1Down:Connect(function()
    if mouse.Target and mouse.Target.Name == 'GasPump1' and (Player.Character.HumanoidRootPart.Position - mouse.Hit.p).magnitude <= 10 and game.Workspasce((Player.Name.. "Car").Driving.DriverSeat.Position - mouse.Hit.p).magnitude <= 10 then
       if mouse.Target.AlreadyOpened.Value == false then -- stop code if it isnt false
       game.ReplicatedStorage.GiveGas:FireServer()
	    end
	end
end)

here is the server script(other is local) i dont know if this one works to. I assume not seeing as this one does not work.

local re = Instance.new("RemoteEvent",game.ReplicatedStorage)
re.Name = "SpawnSedan"

re.OnServerEvent:Connect(function(Player)
game.Workspace(Player.. "Car").Driving.DriverSeat.Gas.Value = 50
end)
2 Likes

You misspelled Workspace in the first snippet.

Facepalm this was one of the issues, but now im getting a new error, saying "Attempt to index field “driving” (a nil value) here is a screenshot of the setup.

game.Workspace[Player.Name .. "Sedan"].Driving

Honestly, i get what the other ones mean, but this takes the cake for the ones I dont. image

You cannot subtract positions from positions, but you can subtract their individual X Y and Z’s.

Edit: I found out (thanks to @Dysche) that you can subtract them.

2 Likes

This seems to work

local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()

mouse.Button1Down:Connect(function()
    if mouse.Target and mouse.Target.Name == 'GasPump1' and (Player.Character.HumanoidRootPart.Position - mouse.Hit.p).magnitude <= 10 and (game.Workspace[Player.Name .. "Car"].Driving.DriverSeat.Position - mouse.Hit.p).magnitude <= 10 then
       if mouse.Target.AlreadyOpened.Value == false then -- stop code if it isnt false
       game.ReplicatedStorage.GiveGas:FireServer()
	    end
	end
end)

But for some very weird reason, the server script, says PoogliesCar is not a valid member of workspace, its not cloned locally, its just THERE.

local re = Instance.new("RemoteEvent",game.ReplicatedStorage)
re.Name = "GiveGas"

re.OnServerEvent:Connect(function(Player)
game.Workspace(Player.Name.. "Car").Driving.DriverSeat.Gas.Value = 50
end)

The picture of your explorer hierarchy shows that the model is named “PoogliesSedan” rather than “PoogliesCar.”

I have changed that before, I should have notified you in that post.

What do I do if all of you helped me with my issues? I dont want to accept just 1 person’s response.

Why wouldn’t you be able to? They’re Vector3s.

Mark the most useful response as the solution I’d say.

1 Like

To subtract Vector3s you would have to do this:

local Result = (SomeVector3 - SomeVector3).Magnitude

That’s to get the distance between two Vector3s, to subtract you’d just do:

local result = someVector3 - anotherVector3

Also don’t you mean (Could’ve been a typo idk, but you put a comma):

local result = (someVector3 - anotherVector3).Magnitude