So... In filtering enabled when you spawn a car (Localscript) no one else will see your car. I want to make it where players can see your car. I wanted to use a code to get the player through a button.
script.Parent.MouseButton1Click:connect(function(plr) print(plr) end)
Now the problem happens when you press the button. When you press the button I suspected the player name RjsMc
in output, but instead it says nil
. So how would I get the player through a script like this? If there is another method please tell me. (FILTERING ENABLED)
If you want to spawn a car where other players will see it, you need to use Remote Event.
Sample:
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local CarSpawnEvent = ReplicatedStorage:WaitForChild("CarEvent") local GuiButton = script.Parent GuiButton.MouseButton1Down:Connect(function() CarSpawnEvent:FireServer() end)
Server Side:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local CarSpawnEvent = ReplicatedStorage:WaitForChild("CarEvent") local GetCar = game:GetService("ServerStorage"):WaitForChild("Truck") local cloneCar = GetCar:Clone() CarSpawnEvent.OnServerEvent:Connect(function(player) cloneCar.Parent = game.Workspace.SpawnLocation -- Add more to this, like being specific where the car actually spawns. end)
If it's a local script, just use LocalPlayer
local plr = game:GetService("Players").LocalPlayer script.Parent.MouseButton1Click:connect(function()--plr is not a parameter of MouseButton1Click print(plr.Name) end)