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

remote event FE script wont work?

Asked by 5 years ago

so I'm making a script where if you have a badge it makes a certain brick's can collide property set to false only for the client, here's my script that won't work 100%

regular script that's in the brick that i want to be can collide false:

local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")

remote.OnClientEvent:Connect(function(player)
    script.Parent.CanCollide = false
end)

i have a number value and a script that changes the number depending on what badge you have, the local script reads it

here's the local script in the playergui and its a child of the numbervalue:

local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")

if script.Parent.Value == 1 then
    remote:FireClient()
end
0
FireClient needs a player argument but OnClientEvent doesn’t have a player argument saSlol2436 716 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

Your scripts are backwards. The local script should be listening for OnClientEvent, and the server should be firing to the client, and remove the player parameter on OnClientEvent.

-- LocalScript in PlayerGui
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")

remote.OnClientEvent:Connect(function()
    workspace.Part.CanCollide = false -- i don't know where the part is, replace Part with name
end)

Server code under the part:

-- Server script
local Players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")

script.Parent.Touched:Connect(function(part) 
    -- You need to get the player, I will use a Touched event

    local plr = Players:GetPlayerFromCharacter(part.Parent)

    if plr then -- make sure is a player!
        remote:FireClient(plr) -- done
    end
end)
0
thanks man retracee 68 — 5y
Ad
Log in to vote
0
Answered by
yellp1 193
5 years ago

you will need it to look like:

if script.Parent.Value == 1 then
    remote:FireClient(player) -- if a player is specified
end

Answer this question