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

Getting player through button script? (FILTERING ENABLED)

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)

2 answers

✓ Accepted answer

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)

6 comments

0

I didn't test this on studio, but you'll have to edit this because the variables aren't real. Just showing a real example of how it firing the Remote Events work, but if you don't know just make sure you study Remote Events then.

0

Actually, I'd suggest study and practice on Remote Events. Remote Event and Remote Function are the uses for client to server communication, but I'm no master at explaining both well especially since I struggle with Remote Function. http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions , also refer to youtube videos.

0

I know how to use remove events, however not during when filtering enabled is on.

0

Also... Where would I put the server side script? Workspace or ServerScriptStorage?

0

ServerScriptService. For organizational purposes, you may want to put them in a folder, inside server script service.

0

Looks like it works! Thanks!

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)

1 comment

0

Due to Filtering Enabled, its hard to make it where by spawning a car, others can see it.

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