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

Although the script is correct, nothing happens. Can i get help?

Im new at scripting so im trying to make a tycoon game to improve myself. I made a script and it seems correct, there is no any errors on Output but nothing happens when im trying it.

local f = true
local screenn = script.Parent.Parent.Parent.monitor.screen


script.Parent.ChildAdded:Connect(function(Child)
	if Child.Name == "SeatWeld" and f == true then
		f = false
		screenn.BrickColor = BrickColor.new("Steel blue")
		local player = game.Players:GetPlayers()
		if player ~= nil then
			if script.Parent.Parent.Parent.Parent.Parent.Owner.Value == player.Name and f == false then
			local stats = game.ServerStorage.PlayerMoney:FindFirstChild(player)
			stats.Value = stats.Value + 10
			wait(2)
			f = true
				
			end
		end
	end
end)


script.Parent.ChildRemoved:Connect(function(Child)
	if Child.Name == "SeatWeld" and f == false then
		f = true
		screenn.BrickColor = BrickColor.new("Black")
	end
end)

After "if player ~= nil then" part is doing nothing but screen's color is changing. So the error is after this (if player ~= nil then) part. I didnt understand whats wrong with it.

(Btw this scripts goal is when player sitting onto chair, he will get 10 money every 2 seconds and when he isnt sitting then he wouldnt.)

8 comments

0

Do you want to make the player sit on line 10

0

No player is sitting on line 5 when he sits "childadding" connects function

0

What script is it local or server script and what is it placed in?

0

Also on line 9 try local Players = game:GetService("Players")

0

Its server script and can i use local players in server script?

0

Tried local players and didnt worked.

0

Try this in server script [[game.Players.PlayerAdded:connect(function(player) ]]

0

I think its because you didnt reference the player added event.

1 answer

✓ Accepted answer

The error must be that you didn't reference the player when joined so make sure you use a playeradded event. Put this at line 1

Players = game:GetService("Players")
for _,i in pairs(Players:GetPlayers()) do
    print(i.Name .. " Has joined the game")
if player ~= nil then
-- Do something here
end
end

1 comment

0

I really appreciate it man it worked thanks!

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