rostik yankun
rostik yankun

Reputation: 1

bad argument #3 to 'Text' (string expected, got nil)

I'm making a place in roblox. And i wrote script, Look at it, and please, say what wrong with it??? In another scripts all works perfectly!, you can help me with it?

    local players = game.Players:GetChildren()
    local pupil = players[math.random(0,#players)]
    local James = game.Workspace.James
    local Texte = game.StarterGui.ScreenGui.Maintexzt
    local nameq = game.StarterGui.ScreenGui.Maintexzt.Nameq
    function ontouch(hit)
    if hit.Parent:findFirstChild("Humanoid") then
    print("Trigget working!")
    James.Humanoid.Torso.CFrame = game.Workspace.OutOfhere.CFrame
    script.Parent.CFrame = game.Workspace.SpawnLocation.CFrame
end
end
    script.Parent.Touched:Connect(ontouch)
    function ontouchexit()
Texte.Text = "Uh... We did it??"
wait(2)
nameq.Text = players.Name
Texte.Text = "Oh how we make it?"
wait(2)
nameq.Text = James.Name
Texte.Text = "Better, go home!"
wait(3)
nameq.Text = players.Name
Texte.Text = "Go!"
nameq.Text = James.Name
Texte.Text = "But go to my home!"
nameq.Text = players.Name
Texte.Text = "Nope"
nameq.Text = James.Name
Texte.Text = "Your choice, Your die, You can follow me, or not"
end
script.Parent.TouchEnded:Connect(ontouchexit)

and please, say what wrong with it, I want to finish a develop the place.

Upvotes: 0

Views: 2174

Answers (2)

̣̣̣
̣̣̣

Reputation: 33

This could help:

local Workspace     =   game.Workspace or workspace;
local StarterGui    =   game.StarterGui;
local players       =   game:GetService("Players");
-----------------------------------------------------------------------------
local Pupil     =   Players[math.random(0,#Players)];
local James     =   Workspace:FindFirstChild("James");
local Texte     =   StarterGui.ScreenGui:FindFirstChild("Maintexzt");
local nameq     =   StarterGui.ScreenGui.Maintexzt:FindFirstChild("Nameq");
local Target    =   ""; --Stores any string value of players that touched the TouchPart
-----------------------------------------------------------------------------
function ontouch(hit)
    if (hit.Parent:FindFirstChild("Humanoid")) then
        print("Trigger working!");
        Target                      =   hit.Parent.Name;    --Saves value of a player's name
        James.Humanoid.Torso.CFrame =   Workspace.OutOfhere.CFrame;
        script.Parent.CFrame        =   Workspace.SpawnLocation.CFrame;
    end
end
-----------------------------------------------------------------------------
function ontouchexit()
    --Replaced 'players.Name' into 'Target', which contains string
    Texte.Text = "Uh... We did it??"
    wait(2)
    nameq.Text = Target
    Texte.Text = "Oh how we make it?"
    wait(2)
    nameq.Text = James.Name
    Texte.Text = "Better, go home!"
    wait(3)
    nameq.Text = Target
    Texte.Text = "Go!"
    nameq.Text = James.Name
    Texte.Text = "But go to my home!"
    nameq.Text = Target
    Texte.Text = "Nope"
    nameq.Text = James.Name
    Texte.Text = "Your choice, Your die, You can follow me, or not"
    Target = ""; --Resets the value of who previously touched the TouchPart
end
-----------------------------------------------------------------------------
script.Parent.Touched:Connect(ontouch)
script.Parent.TouchEnded:Connect(ontouchexit)

Edit: If it doesn't work, try replacing

function ontouch(hit)
    if (hit.Parent:FindFirstChild("Humanoid")) then

with this

function ontouch(hit)
    if (hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == players.Name) then

That checks whenever the person who touched it is an actual player, not from someone (NPC) who also have a humanoid as well

Upvotes: 1

Piglet
Piglet

Reputation: 28950

local players = game.Players:GetChildren()

https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren

Returns an array (a numerically indexed table) containing all of the Instance's direct children

nameq.Text = players.Name

Not being a Robolox expert I find it very unlikely that players.Name is anything but nil

Your code further suggests that assigning vlaues to those Text properties will call some function. That would explain the error message to me.

I don't think an array of players would say "Uh... We did it??" So I guess the solution to your problem is to find out who you actually want to talk and use that name.

Print players.Name and see for yourself.

Upvotes: 0

Related Questions