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

why is this remote event not sending parameters properly and mixing them up?

Asked by 4 years ago
local player = game.Players.LocalPlayer
local reloadAnim = tool.Animations.R6GlockReload
local reloadSound = tool.Animations.ReloadSound
local reloadEvent = local reloadEvent = replicatedstorage.glockEvents.ReloadEvent

function reload()
    if ammo.Value ~= ammoCapacityStat then 
    local ammoToTake = ammoCapacityStat - ammo.Value
        if reserveAmmo.Value <= 0 then 
            print("no reserve")
            else
            if reloading == false then
                reloading = true
                reloadEvent:FireServer(player,reloadAnim,reloadSound)

Hey guys im trying to send this data to a server script to play a reload animation and reload sound from the server

replicatedStorage.glockEvents.ReloadEvent.OnServerEvent:Connect(function(player,reloadAnim,reloadSound) 
        print (player)
        print (reloadAnim)
        print (reloadSound)

However when this second script outputs instead of outputting like this as i would expect:

StarDestroy, R6GlockReload, ReloadSound

it outputs like this instead

StarDestroy, StarDestroy, R6GlockReload

To me it seems like the script is mixing up the parameters and i don't understand why. I even have this same setup in another part of my script and it works fine. How can i solve this?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

When you use FireServer from user client, it also sends the Player instance to the server as a case to determine which player's client the request is from. That said, you don't need to pass the player instance manually through FireServer, only reloadAnim and reloadSound are enough!

reloadEvent:FireServer(reloadAnim,reloadSound)

The last script is totally correct. Its first argument always return the player instance. Same goes for RemoteFunctions in the same scenario.

I hope this explains it all! Good luck! c:

1
ah that makes sense thanks man StarDestroy 25 — 4y
0
no probss! Afterl1ght 321 — 4y
Ad

Answer this question