Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this happening?

Asked by
novipak 70
10 years ago

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.

0
Try removing the PlayerAdded function, and the end) that ends it. Discern 1007 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

The Changed event is a member of StarterPlayerand 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)

0
Thanks! novipak 70 — 10y
Ad

Answer this question