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

[solved] RemoteEvent sending wrong data?

Asked by 4 years ago
Edited 4 years ago

Im trying to make a handcuff script but the RemoteEvent isnt sending the data that I (probably wrongfully) expect it to.

in the local script I have function to get the players name then in the event script it anchors the HumanoidRootPart, for now Ive just got it printing out the sent data ust to test it

Local script in handcuffs

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local detainedEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("DetainedEvent")

script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        if mouse.Target ~= nil then
            print("clicked on "..mouse.Target:GetFullName())
            local plr = nil
            _, plr = pcall(function()
                return game.Players[mouse.Target.Parent.Name]
            end)
            print(plr)
            if plr ~= nil then
                detainedEvent:FireServer(plr )
                print("Fired")
            else
                print('no player')
            end
        end
    end)
end)

and the event script that is stored in ServerScriptStoeage

-- Player Captured script
local detainedEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("DetainedEvent")
local CapturedPlr = game.ReplicatedStorage.Captured
local function onDetainedFired(player)


    print("server "..player.Character.Name.." Name")

    --player.Character.HumanoidRootPart.Anchored = true
end
detainedEvent.OnServerEvent:Connect(onDetainedFired)

when tested if im player-1 when I read the console it shows Ive clicked on Player-2 but the server says player-1 name was sent over

https://i.imgur.com/01lXcJc.png

https://i.imgur.com/3oJNc60.png

1 answer

Log in to vote
0
Answered by 4 years ago

Ive solved it I needed to add the player parameterin the function

local function onDetainedFired(player, plr)


    print(player.Name.." caught"..plr.Name)

    plr.Character.HumanoidRootPart.Anchored = true
end
Ad

Answer this question