How to make a speed boost code?

Hello developers,
recently I tried to make a code that gives 20 seconds of speed boost. I tried to find everywhere on the internet on how to fix the issue, but I didn’t find anything. I would appreciate if you can help me making a code that gives 10 seconds of speed boost.

Here is what I tried so far:
(localscript )

local rp = game:GetService("ReplicatedStorage")
local remoteevent = rp:WaitForChild("CodeSubmit")

Codes = {
	"100 Visites";
	"200 Visites"
}


script.Parent.MouseButton1Click:Connect(function()
	if Codes[table.find(Codes, script.Parent.Parent.TextBox.Text)] then
		remoteevent:FireServer(script.Parent.Parent.TextBox.Text)
	end
end)

(Script)

local rp = game:GetService("ReplicatedStorage")
local remoteevent = rp:WaitForChild("CodeSubmit")

   remoteevent.OnServerEvent:Connect(function(plr,Code, character)
    	if Code == "100 Visites" then
    		local player = game.Players:GetPlayerFromCharacter(character)
    		local human = character:FindFirstChild("Humanoid")
    		human.WalkSpeed = 50
    		wait(10)
    		human.WalkSpeed = 16
    	end
    end)

(Images)


Any type of help is accepted.
Thanks!

2 Likes

You added a “;” instead of a comma “,”

It could be this part. I see that when the RemoteEvent is fired, you aren’t defining a player’s character.

local CurrentCode = ""
local rp = game:GetService("ReplicatedStorage")
local remoteevent = rp:WaitForChild("CodeSubmit")

Codes = {
	"100 Visites",
	"200 Visites"
}
script.Parent.MouseButton1Click:Connect(function()
 if script.Parent.Text == "" then return end
 CurrentCode = script.Parent.Text
 if Codes[CurrentCode] then
   remoteevent:FireServer(CurrentCode)
 end
end)


You can do this

1 Like

Yes its true. Why bothering do :GetPlayerFromCharacter when you don’t have his character ??
just take it from plr param in the remote event

1 Like

A “;” works just as well as a comma. “,”

As @Exavism said, you are trying to use the character without defining it. Instead, you are unnecessarily defining the player, which you already have a reference for. You can get the character using plr.Character. There’s also another thing that you can change, although it doesn’t cause problems. This if statement

if Codes[table.find(Codes, script.Parent.Parent.TextBox.Text)] then
	remoteevent:FireServer(script.Parent.Parent.TextBox.Text)
end

could be simplified like this

if table.find(Codes, script.Parent.Parent.TextBox.Text) then
	remoteevent:FireServer(script.Parent.Parent.TextBox.Text)
end
1 Like

Never saw “;” replacing comma before.

Codes[CurrentCode] work as well (for me)

It works if the code is used as a key, but in their table the codes are values (the table is an array).

Does’nt he use it as a key ? It could be more efficient.

Yes, using them as the keys would probably be more efficient, at least if he adds more of them.

Thanks, I tried to adjust the scripts, but it still doesn‘t work.

New Scripts:

why are you doing if Code[table.find()] ?

Adding to my reply, when dealing with codes that give you power-ups, you should do it on the server.
rather than checking if the code is correct on the client side, then firing a RemoteEvent that gives the power-up.

I tried your solution, but it doesn‘t work.

Are there any errors in the output?

What solution are you talking about ? Send me your code again .

There is this:
Infinite yield possible on 'ReplicatedStorage:WaitForChild("CodeSubmit")'

That means your remote event isnt in ReplicatedStorage