Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

1 comment

0

Accept the answer.

1 answer

✓ Accepted answer

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)

3 comments

0

Tell me if this helped

0

This worked! Thank you, Nikkulaos!

0

Np

This discussion is preserved as it was. New answers, comments, and votes are closed.