How would I incorporate stunning the player in this run script?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I have a run script here, and I’m wondering how I would incorporate a stun value in this script.

  2. What is the issue? Include screenshots / videos if possible!
    I’m not quite sure how to do it, as I’ve tried but it doesn’t work. (I removed the non working code from the local script you see down below)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried getting help from one of my friends, and I have looked on the devforum.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

My local script

BTW, I have another script that turns the player’s walkspeed and jumppower to 0 when stunned is true.

repeat task.wait() until game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")

local Stunned = game.Players.LocalPlayer.Character.Values.Stun.Value
Stunned = false
local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

local UserInputService = game:GetService("UserInputService")
local StarterPlayer = game:GetService("StarterPlayer")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local DefaultFieldOfView = 70
local DefaultWalkSpeed = 16

local SprintingFieldOfView = DefaultFieldOfView * 1.25
local SprintingWalkSpeed = DefaultWalkSpeed * 1.5

local Stamina = 100
local Sprinting = false

local TweeningTime = 0.3

local LastTaps = {
	W = tick(),
	A = tick(),
	S = tick(),
	D = tick()
}

local HoldingKeys = {}

Camera.FieldOfView = DefaultFieldOfView
Humanoid.WalkSpeed = DefaultWalkSpeed

UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.W  or Input.KeyCode == Enum.KeyCode.A or Input.KeyCode == Enum.KeyCode.S or Input.KeyCode == Enum.KeyCode.D then
		if LastTaps[Input.KeyCode.Name] then
			local TimeDistance = tick() - LastTaps[Input.KeyCode.Name]

			LastTaps[Input.KeyCode.Name] = tick()

			if TimeDistance <= 0.2 and not Sprinting then
				Sprinting = true

				TweenService:Create(Camera, TweenInfo.new(TweeningTime), {FieldOfView = SprintingFieldOfView}):Play()
				Humanoid.WalkSpeed = SprintingWalkSpeed
			end
		end
	end

	if not table.find(HoldingKeys, Input.KeyCode.Name) then
		table.insert(HoldingKeys, Input.KeyCode.Name)
	end
end)

UserInputService.InputEnded:Connect(function(Input)
	if table.find(HoldingKeys, Input.KeyCode.Name) then
		table.remove(HoldingKeys, table.find(HoldingKeys, Input.KeyCode.Name))
	end

	if Input.KeyCode == Enum.KeyCode.W or Input.KeyCode == Enum.KeyCode.A or Input.KeyCode == Enum.KeyCode.S or Input.KeyCode == Enum.KeyCode.D then
		local KeepSprinting = false

		for Keycode, Value in pairs(LastTaps) do
			if table.find(HoldingKeys, Keycode) then
				KeepSprinting = true

				break
			end
		end

		if Sprinting and KeepSprinting == false then
			Sprinting = false

			TweenService:Create(Camera, TweenInfo.new(TweeningTime), {FieldOfView = DefaultFieldOfView}):Play()
			Humanoid.WalkSpeed = DefaultWalkSpeed
		end
	end
end)

RunService.RenderStepped:Connect(function()
	if Sprinting then
		Stamina -= 0.25
	else
		Stamina += 0.25
	end

	Stamina = math.clamp(Stamina, 0, 100)

	if Stamina <= 0 and Sprinting ~= false then
		Sprinting = false

		TweenService:Create(Camera, TweenInfo.new(TweeningTime), {FieldOfView = DefaultFieldOfView}):Play()
		Humanoid.WalkSpeed = DefaultWalkSpeed
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

HI Mate here is a script tht is not mine from a piggy game you might be able to adapt it to your own :

local debounce = false

game.ReplicatedStorage.Stun.OnServerEvent:Connect(function(plr,target)
if target then
if target:FindFirstAncestorOfClass(“Model”) then
– Check to see if clicked model is a real player
local pig = game.Players:GetPlayerFromCharacter(target:FindFirstAncestorOfClass(“Model”))

		if pig then
			if pig:FindFirstChild("Piggy") then -- Check to see if it is actually Piggy or just another contestant
				if not debounce then
					
					local stunTag = Instance.new("BoolValue") -- Add stun tag so that we can check in other scripts such as Piggy Bat script whether Piggy is stunned or not
					stunTag.Name = "Stunned"
					stunTag.Parent = pig
					
					if pig.Character:FindFirstChild("Head") then
						-- Add confusion sparkles to show Piggy is stunned
						local Sparkles = Instance.new("Sparkles")
						Sparkles.Parent = pig.Character:FindFirstChild("Head")
						Sparkles.SparkleColor = Color3.fromRGB(255,255,255)
					end
					
					-- Announce to all players in GUI that Piggy is stunned
					
					game.ReplicatedStorage.Announcement:FireAllClients("The Creature is gone for 20 seconds")
					-- Enable debounce so stun effect cannot be applied again for 20 seconds
					debounce = true
					-- Freeze pig by setting walkspeed to 0
					pig.Character.Humanoid.WalkSpeed = 0
					wait(20) -- wait 20 sec before enabling walkspeed again to 14 and then setting debounce to false so
					-- that the piggy can be stunned again
					pig.Character.Humanoid.WalkSpeed = 22
					debounce = false
					-- At the end of the debounce, remove sparkles
					if pig.Character then
						if pig.Character:FindFirstChild("Head"):FindFirstChild("Sparkles") then
							pig.Character:FindFirstChild("Head"):FindFirstChild("Sparkles"):Destroy()
						end
					end
					
					pig:FindFirstChild("Stunned"):Destroy() -- Delete stunned tag so we can tell from other scripts that the
					-- piggy is no longer stunned.
				end
			end
		end		
	end
end

end)

I uh, dont like this piggy script, piggy is also a dead game, lol.

all good, good luck with it :slight_smile:

First off I do recommend making the stun value a number value rather than a Bool Value since a Bool Value would only support tow states false and true while a Number value could handle multiple stuns at the same time so you would just have to add 1 to the number value and remove 1 at a later time

Secondly you would just have to do this

if Stunned.Value == true then return end

or with the number stun

if Stunned.Value >= 1 then return end

Hope this helps

You aren’t suppose to be able to be stunned multiple times.

1 Like

I still do recommend it also use the

if Stunned.Value == true then return end

for what you want