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

Why is this not returning the right name/ tool?

Asked by 4 years ago

Basically making a sword fighting system and for some odd reason when I fire the event it returns the actual player and the players name.

-- LOCAL
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
    if player.Character.ExtraData.Armed.Value == true then
local WeaponName1 = script.Weap.Value 
local WeaponName = WeaponName1
print(WeaponName)
print("Is armed L")
if player.Character:FindFirstChild(WeaponName) then
    print("Found Weapon L")
local Weapon = player.Character:FindFirstChild(WeaponName)
    game.ReplicatedStorage.Combat.Slash:FireServer(player, Weapon)
end
end
end)
-- SERVER
local thing1 = game.ReplicatedStorage.Combat.Slash
thing1.OnServerEvent:connect(function(player, Weapon)
    print("Slash Fired S")
    print(Weapon.Name)

That is the only part of the serverscript it does, yes the actual script has ends and all that. But you see when it prints the sword name for the local it prints ("Starter") (The sword name) but when it prints for the server it prints my username. I have also tried to just send the name of the item instead of the item itself to the server and it still won't work at all and just sends my username on the server.

1 answer

Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
4 years ago

You don't need to send the player through the localscripts arguments try only sending the weapon tell me if it works or not

-- LOCAL
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
    if player.Character.ExtraData.Armed.Value == true then
local WeaponName1 = script.Weap.Value 
local WeaponName = WeaponName1
print(WeaponName)
print("Is armed L")
if player.Character:FindFirstChild(WeaponName) then
    print("Found Weapon L")
local Weapon = player.Character:FindFirstChild(WeaponName)
    game.ReplicatedStorage.Combat.Slash:FireServer(Weapon)
end
end
end)
0
How would the server script know what the "player" is then? XX_Doggoa 24 — 4y
0
The server script knows the player by default when using a remote event theirs no need to define it Prestory 1395 — 4y
0
for me its erroring. XX_Doggoa 24 — 4y
0
What does it say? Prestory 1395 — 4y
View all comments (10 more)
0
its just underlining lots of variables. (Red underline XX_Doggoa 24 — 4y
0
did u get rid of it from the server script too? Prestory 1395 — 4y
0
also it needs the player so it can make them use a animation and make sure they are already not attacking XX_Doggoa 24 — 4y
0
Yes I did change it on the server too XX_Doggoa 24 — 4y
0
thing1.OnServerEvent:connect(function(player, Weapon) keep this the same just remove it from game.ReplicatedStorage.Combat.Slash:FireServer(Weapon) Prestory 1395 — 4y
0
don't remove player from the server Prestory 1395 — 4y
0
Just did what you said its work except no animation and no damage. but all the prints except for one in the middle work. XX_Doggoa 24 — 4y
0
nvm fixed animation XX_Doggoa 24 — 4y
0
Alright so it worked? Prestory 1395 — 4y
0
I'm still making sure it works 100% before accepting the ans XX_Doggoa 24 — 4y
Ad

Answer this question