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

Why is my remote function reading both arguments as "player"?

Asked by 6 years ago

I have a local script inside of a surface gui, inside of the starter gui.
Here's the local script:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local skinsPanel = playerGui:WaitForChild("SkinsPanel").Frame
local purpleSand = skinsPanel:FindFirstChild("PurpleSand")
local skinColorEvent = game.ReplicatedStorage:WaitForChild("SkinColorEvent")

function onPurpleSand()
    local colorName = Instance.new("StringValue")
    colorName.Value = "PurpleSand"
    colorName.Parent = player.Backpack
    skinColorEvent:FireServer(player,colorName)
end

purpleSand.Activated:Connect(onPurpleSand)

Inside server script storage is the following script:

local skinColorEvent = Instance.new("RemoteEvent")
skinColorEvent.Parent = game.ReplicatedStorage
skinColorEvent.Name = "SkinColorEvent"

skinColorEvent.OnServerEvent:Connect(function(player,colorName)
    local character = player.Character
    local backpack = character:FindFirstChild("Container")
    local colorPart = backpack:FindFirstChild("Handle")
    local skinFolder = game.ReplicatedStorage:WaitForChild("Skins")
    print(colorName.Value)
    local skin = skinFolder:FindFirstChild(colorName.Value).Texture.Texture
end)

However, when skinColorEvent function is called, the server script is reading both arguments as player.

player = player1

colorName = player1

Why is my remote function not carrying the string value that I assign to it in the local script?

0
Accept the answer. cabbler 1942 — 6y

1 answer

Log in to vote
0
Answered by
Nikkulaos 229 Moderation Voter
6 years ago
Edited 6 years ago

When firing servers from the client, you do not need to fire the "player" part, only your variables.

It would instead be this:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local skinsPanel = playerGui:WaitForChild("SkinsPanel").Frame
local purpleSand = skinsPanel:FindFirstChild("PurpleSand")
local skinColorEvent = game.ReplicatedStorage:WaitForChild("SkinColorEvent")

function onPurpleSand()
    local colorName = Instance.new("StringValue")
    colorName.Value = "PurpleSand"
    colorName.Parent = player.Backpack
    skinColorEvent:FireServer(colorName)--This is where the error was
end

purpleSand.Activated:Connect(onPurpleSand)
0
Tell me if this helped Nikkulaos 229 — 6y
0
This worked! Thank you, Nikkulaos! Buggims 4 — 6y
0
Np Nikkulaos 229 — 6y
Ad

Answer this question