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

How to convert object to string or find a different way around my problem?

Asked by
Galicate 106
6 years ago

On lines 13/14 of the Event Receive Script I get the error "ServerScriptService.RecieveEvents:13: bad argument #2 to '?' (string expected, got Object)" How can i fix this or find a way around it?

--Event FireScript

-----------------------Events---------------------------------------
local CharacterChosen = game:GetService("ReplicatedStorage").CharacterChosen
----------------------Workspace Models---------------------------------------
local RecruitLoadoutModel = workspace.Recruit
local DecoyLoadoutModel = workspace.Decoy
local StrikerLoadoutModel = workspace.Striker
local CaliaLoadoutModel = workspace.Calia
local BlasterLoadoutModel = workspace.Blaster
-----------------------Player Models---------------------------------------
local RecruitCharacterModel = game:GetService("ServerStorage").Recruit
local StrikerCharacterModel = game:GetService("ServerStorage").Striker
local DecoyCharacterModel = game:GetService("ServerStorage").Decoy
local CaliaCharacterModel = game:GetService("ServerStorage").Calia
local BlasterCharacterModel = game:GetService("ServerStorage").Blaster
local Player = game.Players.LocalPlayer
-----------------------Functions---------------------------------------
function Recruit()
    print("Clicked")
    local Character = Recruit
    if RecruitLoadoutModel.Availability.Value == true then
        print("trying to fire event")
        CharacterChosen:FireServer(Player, Character)
        print("fired from local")
    end
end
function Striker()
    print("Clicked")
    local Character = Striker
    if StrikerLoadoutModel.Availability.Value == true then
        CharacterChosen:FireServer(Player, Character)
    end
end
function Decoy()
    print("Clicked")
    local Character = Decoy
    if DecoyLoadoutModel.Availability.Value == true then
        CharacterChosen:FireServer(Player, Character)
    end
end
function Calia()
    print("Clicked")
    local Character = Calia
    if CaliaLoadoutModel.Availability.Value == true then
        CharacterChosen:FireServer(Player, Character)
    end
end
function Blaster()
    print("Clicked")
    local Character = Blaster
    if BlasterLoadoutModel.Availability.Value == true then
        CharacterChosen:FireServer(Player, Character)
    end
end
-----------------------Connect Functions---------------------------------------
script.Parent.Recruit.MouseButton1Click:connect(Recruit)
script.Parent.Striker.MouseButton1Click:connect(Striker)
script.Parent.Decoy.MouseButton1Click:connect(Decoy)
script.Parent.Calia.MouseButton1Click:connect(Calia)
script.Parent.Blaster.MouseButton1Click:connect(Blaster)

--Event ReciveScript

--Receiving RemoteFuction Script
-----------------------Events---------------------------------------
local CharacterChosen = game:GetService("ReplicatedStorage").CharacterChosen
-----------------------Player Models---------------------------------------
local TheRecruitCharacterModel = game:GetService("ServerStorage").Recruit
local TheStrikerCharacterModel = game:GetService("ServerStorage").Striker
local TheDecoyCharacterModel = game:GetService("ServerStorage").Decoy
local TheCaliaCharacterModel = game:GetService("ServerStorage").Calia
local TheBlasterCharacterModel = game:GetService("ServerStorage").Blaster
-----------------------Functions---------------------------------------
function ChoseCharacter(Player, Character)
    print("fired from server")
    workspace[Character].Availability.Value = false
    workspace[Character].Head.GUI.Availability.Text = Player.Name
    local ClonedModel = game:GetService("ServerStorage")[Character]:Clone()
    ClonedModel.Parent = workspace
    ClonedModel.Name = Player.Name
    Player.Character = ClonedModel
    workspace.CurrentCamera:Destroy()
    wait()
    workspace.CurrentCamera.CameraType = "Custom"
    workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character[("Humanoid")]
end
-----------------------Connect Functions---------------------------------------
CharacterChosen.OnServerEvent:Connect(ChoseCharacter)

0
Why do you have "[Character]" on lines 13 and 14? JarFullOfMayonnaise 48 — 6y
0
Because the character name is chosen depending on which button they pressed, so the name is never the same. So i used local Character as the model name. Galicate 106 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The script is erroring because you are trying to get the Character by searching it on the workspace using the actual object, not it's name.

An example of this would be:

local Person = workspace.Person
local Character1 = workspace[Person.Name] -- This will work! The argument provided is a string.
local Character2 = workspace[Person] -- This will not work! The argument is an object.

What you are doing is redundant, too. You don't need to index it like "workspace[Character.Name]" since you already got the Character object. Using just "Character" will do fine.

Also, unless the second argument "Character" is a character of a different player, you should just have the first argument "Player" and use the Character property of the Player object.

Ad

Answer this question