Currently I’m trying to enable GlobalShadows on the client-side from a .Touched event on a Server Script. I have a server script within the part using the .Touched event and a Local Script in StarterPlayerScripts.
Remote events are usually called from the client which will be :FireServer() and can be received from the server using :OnServerEvent.
However, when calling from the server, you can do :FireClient or :FireAllClients (I think, it may only be for local events) and can be recieved in the local script (OnClientEvent).
My bad, I accidentally included Maps.PowerOutage here when I forgot that I had edited the scripts. Thank you for pointing that out, I’ve now edited the OP.
(I was really tired when writing the OP lol)
So basically, correct me if im wrong, the only way to get :FireClient() to work is to actually have a player to send with it, so get the character when they touch the part, do charactertoplayer, and sent it with the player, and i also reccomend putting the localscript in playergui
Call the GetPlayerFromCharacter() function provided by the Players service, since FireClient() requires a player object to detect for
local DB = false
script.Parent.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if not DB and Player then
DB = true
game.ReplicatedStorage.Events.EnableShadows:FireClient()
wait(1)
DB = false
end
end)
Touched returns back the Part that it hit, not the Player itself
You’ll have to reference the Player instead by getting the Character Model (That’s inside the workspace) using the GetPlayerFromCharacter() function, which if valid returns back the Player object for the RemoteEvent:FireClient() function to send
Thank you, this worked! Here is the final script used:
local part = script.Parent
local Players = game:GetService("Players")
part.Touched:Connect(function(other_part)
local player = Players:GetPlayerFromCharacter(other_part.Parent)
if player then
game.ReplicatedStorage.Events.EnableShadows:FireClient(player)
end
end)