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

Argument converts to something else when going through a RemoteFunction?

Asked by
drew1017 330 Moderation Voter
8 years ago

LocalScript:

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        workspace.RFpurchase:InvokeServer(lplayer, nearShop)
    end
end)

repeat wait(.5) until lplayer.PlayerGui.Hud.Overlay
local overlay = lplayer.PlayerGui.Hud.Overlay
while wait(.1) and lplayer.Character.Humanoid.Health > 0 do
    print(nearShop) -- ''HealthCrateShop'' or ''false'' depending on whether the If statement below passed
    for i, v in pairs(workspace:GetChildren()) do
        if v:FindFirstChild'Shop' then
            local distance = (v.ShopPart.Position - lplayer.Character.Torso.Position).magnitude
            if distance < 10 then
                nearShop = v
                overlay.Visible = true
                overlay.Text = v.OverlayText.Value
            else
                overlay.Visible = false
                nearShop = false
            end
        end
    end
end

ServerScript: (inside the shop part)

bought = false
price = 150
function workspace.RFpurchase.OnServerInvoke(lplayer, nearShop)
    print(nearShop) -- ''Player1'' regardless of what was printed in the localscript
    if lplayer and lplayer.Character:FindFirstChild('Humanoid') and nearShop == script.Parent then
        if lplayer.Character.Humanoid.coins.Value >= price then
            lplayer.Character.Humanoid.coins.Value = lplayer.Character.Humanoid.coins.Value - price
            if not bought then
                bought = true
                for i=1, 7 do
                        local pickup = game.ReplicatedStorage.pickup:Clone()
                    pickup.BillboardGui.ImageLabel.ImageColor3 = Color3.new(0, 0, 1) -- hp
                    pickup.Parent = workspace
                    pickup.Position = script.Parent.lite.Position
                    pickup.Velocity = Vector3.new(math.random(-25, 25), 25, math.random(-25, 25))
                    pickup:BreakJoints()
                end
                script.Parent.lite:Destroy()
            end
        end
    end
end

This is probably something to do with me getting remotefunction arguments mixed up, but I don't know what I did wrong, so i'd like some help.

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

OnServerInvoke has two arguments. The first is the player who's client invoked the server, and the second is a variant for any other arguments you want to pass. Take a look at both of these:

RemoteFunction:InvokeServer(...)

RemoteFunction.OnServerInvoke(player, ...)

See how player is sent as an argument automatically? What your doing is this:

RemoteFunction:InvokeServer(lplayer, nearShop)

RemoteFunction.OnServerInvoke(player, lplayer, nearshop)

When you write workspace.RFpurchase.OnServerInvoke(lplayer, nearShop) the arguments your are actually receiving is the automatic argument of player and the player you sent as your first argument.

0
I hope that made sense to you! BlackJPI 2658 — 8y
Ad

Answer this question