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

My script only works in Studio test mode, what's the issue here?

Asked by 8 years ago

I have been working on a script for a friend. He wants a chair that restricts jumping so that people can't jump off a horse once they get on. I have been working on this script for a while now and I thought it was working, but he told me it wasn't working. Later on down the road I realized it wasn't working in game, but it worked in Studio test mode. I have looked up this issue for a long time now and I can't seem to get it to work in game at all. Any help or suggestions are greatly appreciated, or maybe other ways I could write this script?

function chaining(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil and game.Players:playerFromCharacter(hit.Parent) then
        if hit.Parent.Humanoid.Health == 0 then return end
        wait(0.4)
        local plr = game.Players:playerFromCharacter(hit.Parent)
        repeat wait() until plr.Character
        local chr = plr.Character
        chr:WaitForChild("Humanoid").Changed:connect(function()
        chr.Humanoid.Jump = false
        end)

    end
end




script.Parent.Touched:connect(chaining)

EDIT: Yes, I have tried running this as both a localscript and a regular script, and to no avail. I will try to change the name of the SeatWeld, thanks for the tip. That might be a LOT easier...

RE-EDIT: I made a script that changed the name of SeatWeld whenever it is created, however when attached to the horse it glitched the horse so it doesn't work for the purpose. If anyone has any other scripts that would restrict jumping in a seat, please post them. Or if they can find an issue with my script...

2 answers

Log in to vote
1
Answered by 8 years ago

Nothing is wrong with the code.

The problem is the fact that you are seeking information about players.

I recommend using a localscript and not a regular script.

Ad
Log in to vote
0
Answered by 8 years ago

I noticed when a player sits on the seat a new Instance is created. It is called SeatWeld and when you rename it, the player who was sitting on the seat can "get out" but not move. I tested this method on a moving object and the movement was a little finicky, but it is the perfect movement for a horse.

Answer this question