Instance Not Being Created

Hey everyone

I have this script inside ServerScriptService

local Module = require(script.Parent:WaitForChild("ServerAdmin"):WaitForChild("ModuleScript"))

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local Warning = Instance.new("IntValue")
		Warning.Name = "Warnings"
		Warning.Value = Module.LoadWarnings(player)
		Warning.Parent = player
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	Module.SaveWarnings(player)
end)

but The IntValue Is not created

Thanks for reading.

1 Like

local Warning = Instance.new("IntValue", game.Workspace)
or

local Warning = Instance.new("IntValue")
Warning.Parent = game.Workspace
1 Like

Why workspace?

And I tried it already still not working

if you turned ON team create, then close your script, and try again

1 Like

and there will be a message output that say “yourUsername applied script to ScriptName”

1 Like

Still not working but thanks

()

Rip… but idk why your username is HackItsGood because HackIsntGood
Anyways, if it don’t work, then idk how to help you…

2 Likes

I can confirm that the value is in fact created, so the issue is most likely related to your code stopping at the module script method. Any errors displayed in the output? In case you’d like this value to be inserted into player’s character, you have to parent it there instead. Could it be that you are looking for the value on the wrong spot?

image

EDIT
Does the value spawn in this case?

Code
-- local Module = require(script.Parent:WaitForChild("ServerAdmin"):WaitForChild("ModuleScript"))

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local Warning = Instance.new("IntValue")
		Warning.Name = "Warnings"
		-- Warning.Value = Module.LoadWarnings(player)
		Warning.Parent = player
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	Module.SaveWarnings(player)
end)


EDIT 2
@SOTR654 you were right, it was a path problem. Just in case you were wondering, both, this and ServerAdmin script were stored inside ServerScriptService, to which you can’t refer with

-- Incorrect
local ServerScriptService = script.Parent
-- Correct
local ServerScriptService = game:GetService("ServerScriptService")
-- or
local ServerScriptService = game:FindService("ServerScriptService")

The difference between :GetService() and :FindService() is that the former doesn’t create required service in case it doesn’t find it in game.

As for require(), it’s lua global that doesn’t allow any time out arguments, however, the following for scenarios apply.

  1. require() without an argument, with an invalid argument.
local Module = require()

-- OUTPUT
-->> Attempted to call require with invalid argument(s).
  1. require() with yielding :WaitForChild().
local Module = require(script:WaitForChild("ModuleScript")) -- no module

-- OUTPUT
-->> Infinite yield possible on 'ServerScriptService.Script:WaitForChild("")
  1. require() wrapped in / secured with pcall().
pcall(function()
	local module = require() -- invalid argument
end)
print("Hello beautiful world!") -- prints
  1. require() wrapped in / secured with pcall(), but combined with :WaitForChild() and no time out causes infinite yield.

It is true that require() used with :WaitForChild(), time out, and wrapped in pcall() works, but usually doesn’t change anything for better, as the script often need module scripts if they require them.

2 Likes

Yes, maybe the script is disabled
You maybe need to rejoin studio, it can be a client bug

Screenshot_20

Can you add a print statement after you set the value so we can be sure that module doesn’t yield the code for some reason?
Like this?

local Module = require(script.Parent:WaitForChild("ServerAdmin"):WaitForChild("ModuleScript"))
print("Module required.")
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local Warning = Instance.new("IntValue")
		Warning.Name = "Warnings"
		Warning.Value = Module.LoadWarnings(player)
        print("Module.LoadWarnings returned a value.")
		Warning.Parent = player
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	Module.SaveWarnings(player)
end)
1 Like

You’re using a server script, not a local script, right?

1 Like

Yes, I’m using server script

(30 ).

1 Like

EDITED
You only need the player.PlayerAdded event, because even if the character is removed, the instances under the player will remain.

local Module = require(script.Parent:WaitForChild("ServerAdmin"):WaitForChild("ModuleScript"))

game.Players.PlayerAdded:Connect(function(player)
	local Warning = Instance.new("IntValue")
	Warning.Name = "Warnings"
	Warning.Value = Module.LoadWarnings(player)
	Warning.Parent = player
end)

game.Players.PlayerRemoving:Connect(function(player)
	Module.SaveWarnings(player)
end)

I added the character added because It didn’t work like you said

Also, Im not sure if this is the case but whenever I have a characterAdded event it only fires once the character has died and respawned, for me anyway it never works when a player loads in for the first time.
So I would recommend using @JollyGameCrazy method.

2 Likes

Well that doesn’t do any good.

1 Like

I have also a module script
Do you think its breaking the script?
All the other scripts running correctly!

When I call the function it’s just getting values from DataStore

If you are testing in studio the player might load before the PlayerAdded event is firing, you can test this by adding a print("player joined") inside of the player added block aswell as adding a print check inside of the character added block.

1 Like

What is showing in the output?