Workspace.Button Simulator.Types.Worlds.Model.Portal.Script:7: attempt to index nil with 'Character' (Full function doesn't work)

Hello guys, while I was doing the new (Huge) update from Button Simulator, I had this issue.


Script:

local Player = game:GetService("Players")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	game.Players.LocalPlayer.Character.Humanoid = script.Parent.Touched:Connect(function() -- This line errors.
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			game.Players.LocalPlayer.Character.PrimaryPart.CFrame = game.Workspace["Button Simulator"].Types["Tp THINGS"]["World 2"].TPPart.CFrame
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch() -- This line also errors because it's a function that's starts at Line 6.

Video:

The issue appeared before the game starts.
And the video is broken… unfortunately.


Image:

Yeah, because it already says on the title, I don’t need to put any images.
You can see of what it is.


So yeah guys, any help is appreciated.

2 Likes

Check if the module is on client

local Player = game:GetService("Players")
local RunService = game:GetService("RunService")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	if RunService:IsServer() then
		return
	end
	
	game.Players.LocalPlayer.Character.Humanoid = script.Parent.Touched:Connect(function() -- This line errors.
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			game.Players.LocalPlayer.Character.PrimaryPart.CFrame = game.Workspace["Button Simulator"].Types["Tp THINGS"]["World 2"].TPPart.CFrame
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch() -- This line also errors because it's a function that's starts at Line 6.

You can no longer use .character on the client side. Instead, use workspace:FindFirstChild(player.Name) to find the player in the workspace.

Also, instead of warning in the console log, you should show the player directly how many ‘Ultra Rebirths’ they need using a text-label or something.

game.Players.LocalPlayer

It is on the client

Players.LocalPlayer is always nil on the server, I think It gave the error because it is basically just nil.Character

2 Likes

That makes no sense, you can always use Character on the client.

This is what the error means. It’s always a little confusing at first because you assume it means Character is nil, but it actually means the thing before it is nil.

1 Like

I don’t know. Recently, Roblox has been throwing errors at me whenever I try to use .character on the client, so the only way around it for me is to just get the character directly from the workspace.

Yeah, your script uses game.Players.LocalPlayer which you can only use in a local script or it will error. Also, what is the script’s parent? In your function you used script.Parent.Touched, but what is the script parented to?

The Script’s parent is the Portal.

What I meant is what is the parent’s classname. Is it a mesh? is it a part? What is it?

Yes

So, I tried to change the line 7 to a literal WaitForChild but I get this error:

One time, the game won’t even load.

This only happened at 60 FPS, but now, at about 240 FPS, the game loads.

local Player = game:GetService("Players")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	game.Players:WaitForChild("Model").Humanoid = script.Parent.Touched:Connect(function()
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			game.Players:WaitForChild("Model").PrimaryPart.CFrame = game.Workspace["Button Simulator"].Types["Tp THINGS"]["World 2"].TPPart.CFrame
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch()

I changed the script to make it more “complex” but…

local Player = game:GetService("Players")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch(hit)
	local plr = game.Players:GetPlayerFromCharacter(game.Players.LocalPlayer)
	script.Parent.Touched:Connect(function()
		if plr["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			game.Players:WaitForChild("Model").PrimaryPart.CFrame = game.Workspace["Button Simulator"].Types["Tp THINGS"]["World 2"].TPPart.CFrame
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch()
local Player = game.Players.LocalPlayer
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	game.Players.LocalPlayer.Character.Humanoid = script.Parent.Touched:Connect(function() -- This line errors.
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			game.Players.LocalPlayer.Character.PrimaryPart.CFrame = game.Workspace["Button Simulator"].Types["Tp THINGS"]["World 2"].TPPart.CFrame
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch()

Try this.

Still errors.

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	Humanoid = script.Parent.Touched:Connect(function()
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			character.PrimaryPart.CFrame = game.Workspace["Button Simulator"].Types["Tp THINGS"]["World 2"].TPPart.CFrame
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch()

If that doesn’t work, try this instead:

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	script.Parent.Touched:Connect(function()
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			character.PrimaryPart.CFrame = game.Workspace["Button Simulator"].Types["Tp THINGS"]["World 2"].TPPart.CFrame
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch()

The 1st script errors.

bandicam 2022-10-22 14-02-34-524

And the second one as well.

So both of the scripts has the same line error.

Follow the steps below, and don’t move your script to another location. There are 6 Steps, make sure you don’t skip any of them.

Step1. Change your script’s RunContext to Client
Screenshot_20221022_104111
This will turn your script into a local script.
Screenshot_20221022_104159

Step2. Insert a RemoteFunction into ReplicatedStorage
Screenshot_20221022_104550
Since the script is now a LocalScript, we will use a RemoteFunction to send data to the server.

Step3. Rename the RemoteFunction to “RemoteFunctionForPortalScript”
Screenshot_20221022_104749
This will allow the RemoteFunction to be called in our LocalScript.

Step4. Add some script to your LocalScript

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	script.Parent.Touched:Connect(function()
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			game.ReplicatedStorage.RemoteFunctionForPortalScript:InvokeServer()
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch()

Paste this code into your LocalScript.

Step5. Add a Script into ServerScriptService
Screenshot_20221022_111037
Screenshot_20221022_111232

Step6. Add some script into your Script

game.ReplicatedStorage.RemoteFunctionForPortalScript.OnServerInvoke = function(player, part)
	local character = player.Character or player.CharacterAdded:Wait()
	character.PrimaryPart.CFrame = game.Workspace["Button Simulator"].Types["Tp THINGS"]["World 2"].TPPart.CFrame
end

Paste this code into your Script.

Now I get this issue:

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	script.Parent.Touched:Connect(function()
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			game.ReplicatedStorage.RemoteFunctionForPortalScript:InvokeServer()
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch()
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
task.wait()

script.Parent.Gui["Title (Required)"].Text = "You need at least "..script.Config["Required Value"].Value.." Ultra Rebirth."

local function touch()
	script.Parent.Touched:Connect(function()
		if game.Players["Ultra Rebirth"].Value >= script.Config["Required Value"].Value then
			game.ReplicatedStorage.RemoteFunctionForPortalScript:InvokeServer()
		elseif game.Players["Ultra Rebirth"].Value <= script.Config["Required Value"].Value then
			warn("You do not have "..script.Config["Required Value"].Value.." Ultra Rebirth. Get "..script.Config["Required Value"].Value-game.Players.LocalPlayer.leaderstats["Ultra Rebirth"].Value.." Ultra Rebirth more !")
		end
	end)
end

return touch

bruh the () on the end, Return the function not fire the function, anyways its fixed

I think

1 Like