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

Why is this happening?

So in my game I have modified the StarterPlayer's values. However, when a player joins, it seems as though all of the values are switched back to default. Afterwords, I made this script in an attempt to stop this from happening, but it seems to have done nothing but throw this error:

16:25:27.773 - Workspace.cam_setter:4: attempt to index field 'CameraMinZoomDistance' (a number value) 16:25:27.775 - Stack Begin 16:25:27.776 - Script 'Workspace.cam_setter', Line 4 16:25:27.777 - Stack End

Here is my code:

game.Players.PlayerAdded:connect(function(plr)
	wait(1)
	local starter = game.StarterPlayer
	starter.CameraMinZoomDistance.Changed:connect(function()
		starter.CameraMinZoomDistance = 10
	end)
	starter.CameraMaxZoomDistance.Changed:connect(function()
		starter.CameraMaxZoomDistance = 30
	end)
	starter.HealthDisplayDistance.Changed:connect(function()
		starter.HealthDisplayDistance = 0
	end)
	starter.NameDisplayDistance.Changed:connect(function()
		starter.NameDisplayDistance = 0
	end)
end)

This is really puzzling me and I would appreciate it a lot if you could help me out with this. Thanks for reading.

1 comment

0

Try removing the PlayerAdded function, and the end) that ends it.

1 answer

✓ Accepted answer

The Changed event is a member of StarterPlayer and not the Integer that It returns.

game.Players.PlayerAdded:connect(function(plr)
    wait(1)
    local starter = game.StarterPlayer

    starter.Changed:connect(function(Prop)
    	if Prop == "CameraMinZoomDistance"  then
        	starter.CameraMinZoomDistance = 10
   	 elseif Prop == "CameraMaxZoomDistance" then
        	starter.CameraMaxZoomDistance = 30
   	 elseif Prop == "HealthDisplayDistance" then
        	starter.HealthDisplayDistance = 0
   	 elseif Prop == "NameDisplayDistance"
        	starter.NameDisplayDistance = 0
	    end
    end)
end)

1 comment

0

Thanks!

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