I to be making an exercising bike and I make this regional script within the seat. It"s an alleged to detect as soon as someone touch the seat. After ~ that, it will launch the OnTouched function. The OnTouched function prints function activated after 3 secs to display that the role has been activated. After the is printed, that will inspect if the player is sitting, and if so, that will print to present that the works and then gives them money. In ~ the minute the output states nothing and also doesn"t publish anything.

You are watching: How to make a seat in roblox

local Player = game.Players.LocalPlayer --Get the player"s character herelocal money = game.Players.LocalPlayer.leaderstats.SeerBuckslocal duty OnTouched(player) wait(3) print("function activated") if Player.Humanoid.Sit == true climate print("If Worked") money.Value = money.Value + 100 endendscript.Parent.Touched:Connect(OnTouched)
0
So do you desire it to speak to script when seat is touched or as soon as someone sit on it? CommanderCaubunsia 126 — 2y
0
Seats have the Occupant building so possibly you have the right to listen for changes on that instead of making use of Touched.. Rheines 661 — 2y
0
Sorry, should have specified. I want it to cause the script when they are sitting sheepposu 561 — 2y

2 answers


Log in come vote
1
*
*

Answered by
*
SerpentineKing 3885
*
*

2 years ago
Local Script

local Player = game.Players.LocalPlayerlocal stats = Player:WaitForChild("leaderstats")local money = stats:WaitForChild("SeerBucks")repeat wait() till Player.Character ~= nil and workspace:FindFirstChild(Player.Name)local character = Player.Characterlocal Humanoid = Character:WaitForChild("Humanoid")local debounce = trueHumanoid.Changed:Connect(function() if Humanoid.Sit == true and also Humanoid:GetState() == Enum.HumanoidStateType.Seated and debounce == true climate debounce = false print("It Worked") money.Value = money.Value + 100 elseif Humanoid.Sit == false and Humanoid:GetState() ~= Enum.HumanoidStateType.Seated and debounce == false climate debounce = true endend)Since you desire this come fire whenever the player sit down, we will certainly be basing our function on the Humanoid.Changed event rather than as soon as the player touch a part

In enhancement to Humanoid.Sit over there is likewise a HumanoidStateType that you can examine to see if the player is seated.

The debounce and elseif statement are supplied so the this event is just fired once until the player has actually stopped sit down.

See more: How To Explain Vr Headset For Lg G4 Vr Headset Reviews, Vr Box For Lg G4 Compatibility

Also, the regional Script will load prior to you can create the leaderstats and SeerBucks instances, so us will usage WaitForChild() come wait till they are uncovered in the player. The same applies to the player Character and also its loading into the workspace.