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

Script points to Player instead of Character?

I'm making an Avengers Simulator game and when they select iron man i want it to change their pants and shirt and add a helmet accessory to their head.

When I click the button this error comes:- Pants is not a valid member of Player "Players.KiaansGTA"

These are my scripts:-

Script for the button

-- Variables
local Button = script.Parent
local Player = game.Players.LocalPlayer.Character
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.IronMan.SuitUp

function OnClick()
	RemoteEvent:FireServer(Player)
end

Button.MouseButton1Down:Connect(OnClick)

Server Script

-- Variables
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.IronMan.SuitUp

local Suit = ServerStorage.IronMan.Suit
local Pants = Suit.Pants.Value
local Shirt = Suit.Shirt.Value


function SuitUp(Player)
	Player.Pants.PantsTemplate = ("rbxassetid://".. Pants)
	Player.Shirt.ShirtTemplate = ("rbxassetid://".. Shirt)
end


RemoteEvent.OnServerEvent:Connect(SuitUp)

And could someone pls copy paste this and put on the official roblox dev page for me? I'm under 13

1 answer

Remote Events always send the player first so the argument you gave is actually the second parameter. However, I recommend that you don't pass the character at all because other people could fire that event and give other players' characters and change their clothing. So remove the "Player" argument and do the SuitUp function like this.

function SuitUp(Player)
   	Player.Character.Pants.PantsTemplate = ("rbxassetid://".. Pants)
   	Player.Character.Shirt.ShirtTemplate = ("rbxassetid://".. Shirt)
end

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