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

Can someone tell me why this script doesnt turn the player into my custom character?

So I have been trying to make a Piggy like a game but my code just won't cooperate I have made a script called game logic and 2 module scripts in it called RoundModule and EventHandling can you tell me why the code doesn't allow the player to become my custom character? here is the game logic script

local Round = require(script.RoundModule)
Round.intermisiion(25)
local chosenChapter = Round.SelectChapter()

local clonedChapter = chosenChapter:Clone()
clonedChapter.Name = "Map"
clonedChapter.Parent = game.Workspace
local Contestants = {}

for i, v in pairs(game.Players:GetPlayers()) do
	if not v:FindFirstChild("InMenu") then
		table.insert(Contestants,v)
	end
end

local chosenPiggy = Round.ChoosePiggy(Contestants)

for i, v in pairs(Contestants) do
	
	if v == chosenPiggy then
		table.remove(Contestants,i)
	else
		game.ReplicatedStorage.ToggleCrouch:FireClient(v,true)
	end
	
end
Round.DressPiggy(chosenPiggy)

here is RoundModule script

local module = {}

local status = game.ReplicatedStorage:WaitForChild("Status")
function module.intermisiion(length)
	for i =length,0,-1 do
		status.Value = "Next round starts in "..i.." seconds"
		wait(1)
	end
end

function module.SelectChapter()
	local rand = Random.new()
	local chapters = game.ReplicatedStorage.Chapters:GetChildren()
	local chosenChapter = chapters[rand:NextInteger(1,#chapters)]
	
	return chosenChapter
end

function module.ChoosePiggy(players)
	
	local Rand = Random.new
	
	local chosenPiggy = players[Rand:NextInteger(1,#players)]
	
	return chosenPiggy
end
function module.DressPiggy(piggy)
	local character = game.ServerStorage.Sasuke:Clone()
	character.Name = piggy.Name
	piggy.Character = character
	character.Parent = game.workspace
end
return module

the event handling one has no code right now so I won't show it, and the errors that show are 15:48:32.758 - ServerScriptService.Game Logic.RoundModule:23: attempt to index function with 'NextInteger',and 15:48:32.759 - Script 'ServerScriptService.Game Logic', Line 16 can you tell me what this problem is?

1 answer

✓ Accepted answer

Hello!

Issue

You forgot to call the Random.new function.

Fix

Simply add a () to your RoundModule ModuleScript.

Fixed RoundModule ModuleScript

local module = {}

local status = game.ReplicatedStorage:WaitForChild("Status")
function module.intermisiion(length)
    for i =length,0,-1 do
        status.Value = "Next round starts in "..i.." seconds"
        wait(1)
    end
end

function module.SelectChapter()
    local rand = Random.new()
    local chapters = game.ReplicatedStorage.Chapters:GetChildren()
    local chosenChapter = chapters[rand:NextInteger(1,#chapters)]

    return chosenChapter
end

function module.ChoosePiggy(players)

    local Rand = Random.new()

    local chosenPiggy = players[Rand:NextInteger(1,#players)]

    return chosenPiggy
end
function module.DressPiggy(piggy)
    local character = game.ServerStorage.Sasuke:Clone()
    character.Name = piggy.Name
    piggy.Character = character
    character.Parent = game.workspace
end
return module

Please accept this answer if it helped!

1 comment

0

wow thx

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