What do you want to achieve? Made a local script that fires a RemoteEvent to the server script when you type “e”
What is the issue? I had a feeling this would happen, the remote event works for everyone in the server, I need to make it only for the player firing the key. I do not want to keep it on a local script because the damage would be weird n’stuff
What solutions have you tried so far?
-- local script
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
anim = Instance.new("Animation")
anim.AnimationId = 'rbxassetid://5320000403'
CanAttack = true
Mouse.KeyDown:Connect(function(key)
if key == "e" then
if CanAttack == true then
CanAttack = false
local playanim = Player.Character.Humanoid:LoadAnimation(anim)
game.ReplicatedStorage.Folder.Technoblade.AttackE:FireServer()
playanim:Play()
wait(10)
CanAttack = true
end
end
end)
-- Server
Sword = script.Parent:WaitForChild("Technoblade")
CanAttack = true
function slash()
Sword.Touched:Connect(function(part)
Hum = part.Parent:FindFirstChild("Humanoid")
if Hum then
Touch = true
else
Touch = false
end
end)
if Touch == true then
Hum.Health = Hum.Health - 25
Sword.Sound:Play()
Touch = false
end
wait(10)
CanAttack = true
end
game.ReplicatedStorage.Folder.Technoblade.AttackE.OnServerEvent:Connect(slash)
Does anyone know a way I can have this work for only one client.
Edit: Forgot to mention I am using this without creating a tool, it is bound to the player at all times. Also don’t question the technoblade lol
The problem is that I want the damage to be sever sided, as if it was in the client the damage would only show for you, is there a way I can transfer the damage to the server side or is that completely impossible?
It is very confusing on what you are asking here. The reason it is firing for everyone is because FireServer fires the event onto the server, basically making the change for everyone. If you want the damage to be on the server side, then that means you want the change to be for everyone. I believe you have the difference between the two messed up, and therefore roblox developer hub has a very good article on this https://developer.roblox.com/en-us/articles/Roblox-Client-Server-Model
If you want a change to be for only one player, then you would do it on the Client via a local script, and therefore a remote will not be needed for this scenario.
This is the confusing part. You said you want the damage to be on the server, but then said you didn’t want the remote to fire for everyone? Can you elaborate on this? Server = Everyone
thx for the help, I meant that I only wanted the person who executed the code does damage, but now that I think of it, thats only obtainable in the client side. The reason I am afraid of doing it on the client side is because damage doesn’t change for the server side, this is the only way I can think of explaining this, sorry if it sounds hazy
I will check out the link, thanks for the help!
When you do damage to someone on a local script, lets say you kill someone, the person you killed will still be alive in their client, you are the only one that can see that person dead. I’ll scrap the idea, I can tell I confused everyone
The client that calls :FireServer() automatically passes the player argument to the :OnServerEvent() listener. You can check if the owner of the sword is the player firing the event using this argument, and then do the damage logic from there.
Example:
function slash(player) --player argument received from :FireServer() and passed through :OnServerEvent()
if game.Players:GetPlayerFromCharacter(script.Parent) == player then --script.Parent is the player's Character. Change this to reference the player's Character if necessary. This also assumes your sword is a tool and if the tool is equipped
--do damage stuff
end
end
game.ReplicatedStorage.Folder.Technoblade.AttackE.OnServerEvent:Connect(slash)
yes because it is a local script. If you want both screens to show the other person as dead (such as I kill someone, he knows he is dead, and everyone sees he is dead) then you would need a server script and not a local script. I think you have a misunderstanding of the 2
Client = Their Computer/Their Rules/ Their Screen
Server = Everyone Sees the change / Actions done on the server, out of the client’s control
In your example you said you didn’t want that happening, which is why you should use the server, not the client