#Code not working

97 messages · Page 1 of 1 (latest)

frank grove
#

I have this code that should make the player no able to jump or press c or shift when his down but it's not working i asked chat GPT for help before coming here and its still not working im a beginner btw and need help


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character


local function disableKeys()
    local function Sink()
        return Enum.ContextActionResult.Sink
    end
    ContextActionService:BindActionAtPriority(
        "DisableKeys",
        Sink,
        false,
        Enum.ContextActionPriority.High.Value,
        Enum.KeyCode.LeftShift,
        Enum.KeyCode.RightShift,
        Enum.KeyCode.C
    )
end


local function enableKeys()
    ContextActionService:UnbindAction("DisableKeys")  
end

-- Function to check if the player is downed
local function isPlayerDowned(player)
    if character and character:FindFirstChild("IsDowned") then
        return character.IsDowned.Value
    end
    return false
end


local function updateKeyState()
    local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")

    if humanoid then
        if isPlayerDowned(player) then
            
            disableKeys()
            humanoid.JumpHeight = 0  -- Disable jumping
        else
        
            enableKeys()
            humanoid.JumpHeight = 7.2 
        end
    end
end
#

its not the whole code

#
local function onCharacterAdded(character)
    local isDowned = character:WaitForChild("IsDowned")
    -- Update key bindings when "IsDowned" changes
    isDowned.Changed:Connect(function()
        updateKeyState()
    end)

    updateKeyState()

    -- Listen for jump changes
    local humanoid = character:WaitForChildOfClass("Humanoid")
    humanoid:GetPropertyChangedSignal("JumpHeight"):Connect(function()
        -- Prevent jumping while downed and restore after standing
        if isPlayerDowned(player) then
            humanoid.JumpHeight = 0 
        else
            humanoid.JumpHeight = 7.2 
        end
    end)

    
    if not isPlayerDowned(player) then
        humanoid.JumpHeight = 7.2
    end
end


player.CharacterAdded:Connect(onCharacterAdded)


if player.Character then
    onCharacterAdded(player.Character)
end
#

this the code

#

i cant send it on one time because i dont have discord nitr

#

Code not working

formal mango
#

ChatGPT is not that create at writing code with semi-complexity or higher. If there are no errors to this script in console I would assume that ContextActionService is being used wrongly, but I don't have experience with that service.

frank grove
#

the thing is

#

i made sure this thing works in other thing

grave plover
#

bro why using "if not" if u got an else

#

no sense

formal mango
#

He didn't write the code

frank grove
#

i didnt

#

write it

wary remnant
#

ok

#

tHen

#

delete the code

#

and write it

frank grove
#

i fixed what i know

#

from the code

#

like the disabling of the keys

grave plover
#

gpt is bad if u just tell him what to do

frank grove
#

because i did in another code

#

i know mostly what i do

#

i can assure u that

#

im a begginer but i understand most of begginer codes

formal mango
#

Instead of disabling the keys I would suggest writing a system that lets you become incapacitated when you have the down bool

frank grove
#

the thing is now halv of tthe code works

#

no

#

when im down

#

an animation plays

#

so u can move

#

but u cant jump and so on but if i made the player incapacitated he will not move at all right?

grave plover
#

bro if he can jump and walk what is the purpose of doing that code?

frank grove
#

no

formal mango
#

If you made your own system you could make the downed state whatever you want

frank grove
#

u dont understand

formal mango
#

You should learn how to make statemachines

frank grove
#

when his down

#

he cant jump or press shift or c

#

and when he stands up

grave plover
#

for jumping its simple

frank grove
#

he still cant do that

#

thats the problem

#

that even if he stands up its still not working

#

but when he is down thats working

formal mango
#

I have no idea what you're saying and thus I don't understand the problem.

grave plover
#

ye

#

can u explain with more details

frank grove
#

ok i will explain last time if u have time for me

grave plover
#

plz

frank grove
#

so

#

when the player gets downed he cant jump or press shift and c and that works

#

but even when the player stands up he still cant jump and press shift and c and i wanna fix that and make him able to jump and press shift and c when he stands up

grave plover
#

just make an frame event

#

to verify that

frank grove
#

can u explain more

#

if u have time

grave plover
#

so in ur script u got verifications right? (ifs)

frank grove
#

yu

#

p

grave plover
#

you know what are frame events or not

frank grove
#

no

#

if its complicated send me a video

grave plover
#

game:GetService("Run Service") ?

frank grove
#

oh yeah

#

i know it not by name

grave plover
#

thats a frame event

frank grove
#

ok

#

got it

grave plover
#

so you do the event and u put all verifications on it

formal mango
#

his changed event should work properly

#

maybe his enablekeys function doesn't work

grave plover
#

yeah thats possible

frank grove
#

so u wanna use heartbeat or something to check if the player still has the bool value?

formal mango
#

frame events are unncessary

grave plover
#

u can use changed too

formal mango
#

You want to keep performance in mind this is a problem that's easily used without frame events

frank grove
#

because i have another code taht should destroy the bool value

#

after some time

grave plover
#
bool.Changed:Connect(function() end)
formal mango
#

ok

#

if it's destroyed then it wont use changed event

#

instead of useing a changed event

#

use a

#

ChildAdded event

#

on your character

#

and check if the character has the isdowned bool value

#

in that event

#

or actually

#

just do something like

#
character.ChildAdded:Connect(function()
updateKeyState()
end)
frank grove
#

k i will try it then

#

but tommorow

#

and i will put some prints if its still not working for any reason

#

thank u for ur time both

#

😄