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

Is there a way to take a StarterPlayerScript and Interact with the Character?

So I'm making this game for fun and I'm trying to make it so when you achieve a certain rank, the game will speed you up. I've tried a couple of places to put this script but I don't know where to do this and how to speed the character up!

(This script ranks the character, and is located in StarterPlayerScripts)

local plr = script.Parent.Parent
local novice = ("Novice")
local exp = ("Expert")
local chgo = ("God Chez")
local loch = ("Lord Chez")
while true do
	wait(0.1)
	if plr.leaderstats.Cheeses.Value == 10 then
		plr.leaderstats.Rank.Value = novice
	end
	if plr.leaderstats.Cheeses.Value == 50 then
		plr.leaderstats.Rank.Value = exp
	end
	if plr.leaderstats.Cheeses.Value == 100 then
		plr.leaderstats.Rank.Value = chgo
	end
	if plr.leaderstats.Cheeses.Value == 500 then
		plr.leaderstats.Rank.Value = loch
	end
end

Is there a way I can take the player and find it's character? I know how to change WalkSpeed, but I don't know how to get the Player's character to do so.

2 answers

✓ Accepted answer

You almost had it!

local plr = game.Players.LocalPlayer
local c = plr.Character or plr.CharacterAdded:wait();
local h = c:WaitForChild("Humanoid");
local novice = ("Novice")
local exp = ("Expert")
local chgo = ("God Chez")
local loch = ("Lord Chez")
local cheeses = plr.leaderstats.Cheeses;
cheeses:GetPropertyChangedSignal:Connect(function() -- set walkspeed wherever you want with 'h.WalkSpeed = number', replacing 'number' with whatever speed you want.
    if cheeses.Value == 10 then
        plr.leaderstats.Rank.Value = novice
    elseif plr.leaderstats.Cheeses.Value == 50 then
        plr.leaderstats.Rank.Value = exp
    elseif plr.leaderstats.Cheeses.Value == 100 then
        plr.leaderstats.Rank.Value = chgo
    elseif plr.leaderstats.Cheeses.Value == 500 then
        plr.leaderstats.Rank.Value = loch
    end
end)

An even more advanced way of doing it (and compressing it) is to use dictionaries.

local plr = game.Players.LocalPlayer
local c = plr.Character or plr.CharacterAdded:wait();
local h = c:WaitForChild("Humanoid");
local novice = ("Novice")
local exp = ("Expert")
local chgo = ("God Chez")
local loch = ("Lord Chez")
local cheeses = plr.leaderstats.Cheeses;
local dictionary = {
  [10] = novice,
  [50] = exp,
  [100] = chgo,
  [500] = loch
} -- Create keys here in the dictionary so we can get them anytime

cheeses:GetPropertyChangedSignal:Connect(function() -- set walkspeed wherever you want with 'h.WalkSpeed = number', replacing 'number' with whatever speed you want.
    if(dictionary[cheeses.Value] ~= nil) then
        plr.leaderstats.Rank.Value = dictionary[cheeses.Value];
    end
end)

Every player object has an object property called Character, to get the character all you need is to call plr.Character

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