Script not working when cloned and parented under Player instance

Okay, so I have a script which clones a IntValue and a Script parented to the IntValue, and the Script is supposed to change the value of the IntValue when it rceives a RemoteEvent.

The problem here is that, the Script just refuses to run after being cloned and enabled. Even the print statement at the top of the Script doesn’t even run after being enabled?

I’ve been looking around the DevForum but there was nothing that really addressed my issue. I’ll link the place file where I’m experiencing the issue here:
BuggyPlace.rbxl (61.2 KB)


Server Scripts:

Server Script for cloning
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
	

	local quizFolder = Instance.new("Folder")
	quizFolder.Name = "quizFolderStats"
	quizFolder.Parent = plr

	local quizTimer = Instance.new("IntValue")
	quizTimer.Name = "quizTimerValue"
	quizTimer.Parent = quizFolder

	local quizTimerScript = script.TimerScript:Clone()
	quizTimerScript.Parent = quizTimer
	quizTimerScript.Enabled = true

	local quizScore = Instance.new("IntValue")
	quizScore.Name = "quizScoreValue"
	quizScore.Parent = quizFolder


end)
Server Script that is being cloned
local countdown = script.Parent
local event = game:GetService("ReplicatedStorage").StartQuizNu
local lastCalled = tick()
print(lastCalled)


event.OnServerEvent:Connect(function(plr)
	if  tick() < lastCalled + 2 then print("Not valid") return end
	lastCalled = tick()

	if countdown.Value ~= 0 then return end -- Only allowed if timer is 0, either by sumbitting or if timer ran out of time naturally.
	countdown.Value = 30 -- Client indicates that new question is starting and needs to restart timer.
	print("Value set.")
end)

countdown:GetPropertyChangedSignal("Value"):Connect(function()
	if countdown.Value == 30 then
		for count = 1, 30, 1 do
			count = countdown.Value
		end
	end
end)

Local Scripts:

Local Script for sending RemoteEvent
local event = game:GetService("ReplicatedStorage").StartQuizNu
local button = script.Parent

button.MouseButton1Up:Connect(function()
	event:FireServer()
	print("Sent!")
end)

Server scripts do not work in the player. Try moving it into a place where server scripts work (SSS, workspace etc.). Now for the countdown thing it gets a little bit more complex

local countdowntable = {}
for i, plr in pairs(game.Players:GetPlayers()) do
  coutdowntable[plr.Name.."'s Countdown"] = plr.quizFolderStats.quizTimerValue
end

Then sub the countdown references in the rest of the script with countdowntable[plr.Name.."'s Countdown"]

1 Like

RunContext is your friend! Normally, scripts under a player wont run, but if you set the RunContext to “Server” it can effectively run anywhere.

RunContext is a property of Script that tells Roblox to run said script as the Server or any client that has the script replicated (this can be a little funky at times), but here, it should be perfect.

Make sure the script is only running when it needs to (using Enabled), as RunContext makes the script run, as I just said, anywhere

1 Like

Works like a charm, thank you @metatablecatmaid and @MysteryX2076 for pointing out the issues on my end!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.