Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 1. When Triggered player is stun for x ammount of seconds
- -- 2. Being stunned means low Jump power, walkspeed etc.
- -- 3. The effect will die off after x ammount of secconds
- local Players = game:GetService("Players")
- local ProximityPrompt = script.Parent.ProximityPrompt
- local plrsDebounceList = {}
- Players.PlayerAdded:Connect(function(player)
- plrsDebounceList[player.Name] = false
- end)
- Players.PlayerRemoving:Connect(function(player)
- plrsDebounceList[player.Name] = nil --> remove the player from list when he leaves the game
- end)
- -- stun config
- local stunDuration = 3
- local statReductionFactors = {
- WalkSpeed = 0.1,
- JumpPower = 0.1,
- JumpHeight = 0.5,
- }
- ProximityPrompt.Triggered:Connect(function(thePlayer)
- if table.find(plrsDebounceList, thePlayer) then return end --> debounce already stunned players
- plrsDebounceList[thePlayer.Name] = true --> debounce
- local humanoid = thePlayer.Character.Humanoid
- local previousValues = {}
- -- Cache pre-stun values
- for propName, _ in pairs(statReductionFactors) do
- previousValues[propName] = humanoid[propName]
- end
- -- reduce properties current values
- for propName, reductionFactor in pairs(statReductionFactors) do
- humanoid[propName] *= reductionFactor
- end
- task.wait(stunDuration)
- -- reset modified properties to their previous values
- for propName, prevValue in pairs(previousValues) do
- humanoid[propName] = prevValue
- end
- plrsDebounceList[thePlayer.Name] = false
- end)
Advertisement
RAW Paste Data
Copied
Advertisement