What do you want to achieve? i want to Fireserver an event but have it only apply to the player who fired it and not to everybody
What is the issue? the event fires and applies to everybody despite the script being local and found in startercharacter (the localscript that fires the event)
What solutions have you tried so far? I tried moving the event to starterplayer to prevent conflicts but that didn’t work either i tried fireclient but that also didnt work. I’m debating to convert the script into normal and put it inside the part itself instead.
--!LOCALSCRIPT
local function v8()
if frame.BackgroundTransparency < 0.36 then
lam:FireServer()
end
end
-!SERVER SCRIPT IN SERVERSERVICE
morph.OnServerEvent:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
if not ServerStorage:FindFirstChild("Characters") then return end
local Character5 = ServerStorage.Characters.Lammy
if not Character5 then return end
if Character and not Engine:IsAlreadyCharacter(player) then
Engine:SetCharacter(player, Character5)
end
end)
Here is the script in local that triggers/calls the “v8 function”
function onTouch(part)
local player = getPlayerFromRootPart(part)
if not player then return end
if table.find(playersTouching, player) then return end
table.insert(playersTouching, player)
local moprhed = parent:FindFirstChild("Morphed")
if moprhed ~= nil then return end
if moprhed == nil then
anim:Play()
tween:Play()
tween.Completed:Wait()
wait(2)
v8(player)
end
end
Per default, :FireServer() will also implicitly send the player instance alongside it, so any changes you do to that specific player, will not apply to all players in the server.
morph.OnServerEvent:Connect(function(player)
local Character = player.Character
local Characters = ServerStorage.Characters.Lammy
if Character and not Engine:IsAlreadyCharacter(player) then
Engine:SetCharacter(player, Characters)
end
end)
Tried your solution but it stil applies to everybody else in the game for some reason.
I tried using print player.Name and it did it too.
game.ReplicatedStorage.LammyMorph.OnServerEvent:Connect(function(player)
print(player.Name," fired the server")
end)
Unfortunately, this makes me believe there’s a problem with your code’s logic, by default, :FireServer() will only apply to the player who’s firing it. Make sure to review your code step by step, by the looks of it, doesn’t look like it should behave this way.
Check out where the event is being fired from and try to identify why all players will also fire it if one does. Post your client’s code here as well and other snippets you might find helpful to pinning down the problem. If I do spot anything, I’ll let you know.
I did countless amount of times, i made sure only the player touching the part is firing server also the localscript is located in startercharacterscript so i also believe it shouldnt behave that way.
Here is the entire localscript function.
local function v8(player)
frame.BackgroundTransparency = frame.BackgroundTransparency - (frame.BackgroundTransparency > 0.36 and player or 0)
if frame.BackgroundTransparency <= 0.36 then
lam:FireServer(player)
end
end
function getPlayerFromRootPart(part)
return part.Name == "HumanoidRootPart" and game.Players:GetPlayerFromCharacter(part.Parent)
end
function onTouch(part)
local player = getPlayerFromRootPart(part)
if not player then return end
if table.find(playersTouching, player) then return end
table.insert(playersTouching, player)
local moprhed = parent:FindFirstChild("Morphed")
if moprhed ~= nil then return end
if moprhed == nil then
anim:Play()
tween:Play()
tween.Completed:Wait()
wait(2)
v8(player)
end
end
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local Modules = ServerScriptService:WaitForChild("Modules")
local Engine = require(Modules:WaitForChild("Engine"))
local morph = game.ReplicatedStorage.LammyMorph
morph.OnServerEvent:Connect(function(player)
local Character = player.Character
local Characters = ServerStorage.Characters.Lammy
if Character and not Engine:IsAlreadyCharacter(player) then
Engine:SetCharacter(player, Characters)
end
end)
I think the issue is with the onTouch function. When the part is touched by a player, it calls the function on all the players because all the players connect the Touched event. So even if the player who touched the part isn’t the local player, it still fires the server.
What you need to do is check if the player who touched the part is actually the LocalPlayer.
local Players = game:GetService("Players")
local function onTouch(part)
local playerWhoTouched = getPlayerFromRootPart(part)
if not playerWhoTouched then
return
end
if playerWhoTouched == Players.LocalPlayer then
-- Do the rest of the code only if playerWhoTouched is the LocalPlayer
end
end