#Firing a Click detector script to the local player
13 messages · Page 1 of 1 (latest)
Imagine that this is a local script
MouseButton1Down:Connect(function()
RemoteEvent:FireServer()
end)
And then this is a server script
RemoteEvent.OnServerEvent:Connect(function(plr)
— plr would be the the player who fired the event
print(“hello”)
end)
This way the print would happen in server, but you’re trying to do it reverse, so you can do:
MouseClick:Connect(function()
RemoteEvent:FireClient(plr) — you must put the player who will listen the event, otherwise it wont work
end)
ohhh and then write what i wrote in the serverscript into the local?
You can do this:
Click detector script:
local DeliveryPart = game.Workspace.DiegosTurf:WaitForChild("DeliveryOutline")
local billboardUi = DeliveryPart.Part:WaitForChild("BillboardGui")
local RS = game:GetService("ReplicatedStorage")
local JobEvent = RS.UiEvent:WaitForChild("ClickJob")
script.Parent.MouseClick:Connect(function(plr)
JobEvent:FireClient(plr)
end)
The local script you made would work
No problem
wait what if im doing a touch script
local diego = game.Workspace.Diego
local RS = game:GetService("ReplicatedStorage")
local JobEvent = RS.UiEvent:WaitForChild("ClickJob")
game.Players.PlayerAdded:Connect(function(plr)
local db = true
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
if db == true then
db = false
JobEvent:FireClient(plr)
local paycheckFrame = plr.PlayerGui.NotificationsUi.PaycheckFrame
local val = Instance.new("IntValue", plr)
val.Name = "val"
val.Value = math.random(450,590) * plr.x2JobsCash.Value
plr.leaderstats.Cash.Value += val.Value
paycheckFrame.desc.Text = "You've been paid $"..val.Value.." Dollars."
wait(3)
paycheckFrame.Visible = false
db = true
end
end
end)
end)
i left the part i want to be updated server sided in here but what should i do in the local part
JobEvent.OnClientEvent:Connect(function()
local db = true
DeliveryOutline.Touched:Connect(function(hit)
if db == true then
db = false
if DeliveryOutline.Transparency == 0.6 then
DeliveryOutline.Transparency = 1
diego.ClickDetector.MaxActivationDistance = 15
DeliveryOutline.Part.BillboardGui.Enabled = false
end
db = true
end
end)
end)