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)
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)
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
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.