Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Getting player through button script? (FILTERING ENABLED)

Asked by
RjsMc 48
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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)
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. liteImpulse 47 — 6y
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. liteImpulse 47 — 6y
0
I know how to use remove events, however not during when filtering enabled is on. RjsMc 48 — 6y
0
Also... Where would I put the server side script? Workspace or ServerScriptStorage? RjsMc 48 — 6y
View all comments (2 more)
0
ServerScriptService. For organizational purposes, you may want to put them in a folder, inside server script service. User#19524 175 — 6y
0
Looks like it works! Thanks! RjsMc 48 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)
0
Due to Filtering Enabled, its hard to make it where by spawning a car, others can see it. RjsMc 48 — 6y

Answer this question