Script not working in game. But work fine in studio. How can i solve this problem

As the title says. I want my script to work in game. But the problem is it’s not working in game but it works completely fine in studio.

3 Likes

Probably a weird problem. Can you show your code?

This can happen for a lot of reasons, since client-server communication in actual game servers isn’t instant, and http requests are made by the Roblox server not your own pc. Also if you’re trying send a request to a website such as discord, requests sent from Roblox servers are blocked, therefore you will have to proxy the request.

be sure u publish it or u committed the scripts u made

1 Like

You could show us your code, or write more detail, because there’s millions of ways this could happen.

CanAttackValue scrupt

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local P1 = game.ServerStorage.CanAttack:Clone()
local P2 = game.ServerStorage.Stun:Clone()
P1.Value = true
P1.Parent = char

end)
end)

Hitbox script

local GG = game:GetService(“Debris”)
local Hitbox1 = game.ServerStorage:WaitForChild(“HitboxXD”)
game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(player)
local Scripta = script:WaitForChild(“Animation”)
local Rep = game.ReplicatedStorage.P1
local Char = player.Character
local CharHuRoot = Char:WaitForChild(“HumanoidRootPart”)
local Hitbox2 = Hitbox1:Clone()
Hitbox2.CFrame = Char.HumanoidRootPart.CFrame + Char.HumanoidRootPart.CFrame.LookVector * 0.8
Hitbox2.Parent = Char.HumanoidRootPart
local Huma = Char.Humanoid
local weld = Instance.new(“WeldConstraint”)
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = Hitbox2
weld.Parent = weld.Part0----
local Debounce = false
local HH = script:WaitForChild(“Animation2”)
local JJ = Huma:LoadAnimation(HH)
local CanAttack = Char:FindFirstChild(“CanAttack”)
local Stun = Char:FindFirstChild(“Stun”)
local Stun1 = game.ServerStorage:WaitForChild(“Stun”):Clone()

if CanAttack and Stun == nil then
Hitbox2.Touched:Connect(function(Hit)
local Char = player.Character
local Hume = Hit.Parent:FindFirstChild(“Humanoid”)
local HumeRooPa = Hit.Parent:FindFirstChild(“HumanoidRootPart”)
local player1 = game:GetService(“Players”):GetPlayerFromCharacter(Hit.Parent) or not Char
if Hit.Parent == Char or Hit.Parent == nil then return end
if Hit.Parent:FindFirstChild(“Accessory”) then
return nil
end
if player1 and Hit.Parent:FindFirstChild(“Humanoid”) and Hit.Parent:FindFirstChild(“HumanoidRootPart”) and Hit.Parent:IsA(“Model”) and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

  		Rep:FireClient(player1)
  		Stun1.Parent = Hit.Parent
  		local Hu1 = Hit.Parent:WaitForChild("Humanoid")
  		local Bovy = Instance.new("BodyVelocity")
  		Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
  		game.Debris:AddItem(Bovy,0.1)
  		Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 67
  		Bovy.MaxForce =  Vector3.new(10000,100000,10000)
  		game.Debris:AddItem(Bovy,0.1)
  		game.Debris:AddItem(Stun1,8)
  		Hume:TakeDamage(15)
  		Hitbox2:Destroy()
  		Debounce = false
  		weld.Part1:Destroy()
  		Hit.Parent.Humanoid:LoadAnimation(Scripta):Play()
  		if Hit.Parent:FindFirstChild("HitboxXD") then
  			game.Debris:AddItem(Hit.Parent:FindFirstChild("HitboxXD"),0)
  		end
  		
  	end
  	
  	if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

  		local Hu1 = Hit.Parent:WaitForChild("Humanoid")
  		Hu1:LoadAnimation(Scripta):Play()
  		local Bovy = Instance.new("BodyVelocity")
  		Bovy.MaxForce = Vector3.new(10000,100000,10000)
  		Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
  		game.Debris:AddItem(Bovy,0.1)
  		Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 67
  		Hume:TakeDamage(15)
  		Hitbox2:Destroy()
  		Debounce = false
  		weld.Part1:Destroy()

  	end
  	
  end)

end
wait(0.1)
weld.Part1:Destroy()
end)

Local Script

local Animation = script:WaitForChild(“Animation”)

local Animation2 = script:WaitForChild(“Animation2”)

local Player = game:GetService(“Players”).LocalPlayer

local Char = Player.Character

local Human = Char:WaitForChild(“Humanoid”)

local Hit = game.ReplicatedStorage:WaitForChild(“Hit”)

local HumanRoot = Char:WaitForChild(“HumanoidRootPart”)

local UIS = game:GetService(“UserInputService”)

local cooldown = 5

local Debounce = false

if Human.Died then

script.Disabled = true

end

UIS.InputBegan:Connect(function(input,IsTyping)

if not IsTyping and not Debounce then

if input.KeyCode == Enum.KeyCode.F then

Hit:FireServer()

Debounce = true

wait(1)

Debounce = false

end

end

end)

Stun script

game.ReplicatedStorage.P1.OnClientEvent:Connect(function()
local Player = game:GetService(“Players”).LocalPlayer
local Char = Player.Character
local Hum = Char:WaitForChild(“Humanoid”)
Hum.WalkSpeed = 0
Hum.JumpHeight = 0
wait(4)
Hum.WalkSpeed = 16
Hum.JumpHeight = 7.2

end)

This script is combat script.

CanAttackValue scrupt

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local P1 = game.ServerStorage.CanAttack:Clone()
local P2 = game.ServerStorage.Stun:Clone()
P1.Value = true
P1.Parent = char

end)
end)

Hitbox script

local GG = game:GetService(“Debris”)
local Hitbox1 = game.ServerStorage:WaitForChild(“HitboxXD”)
game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(player)
local Scripta = script:WaitForChild(“Animation”)
local Rep = game.ReplicatedStorage.P1
local Char = player.Character
local CharHuRoot = Char:WaitForChild(“HumanoidRootPart”)
local Hitbox2 = Hitbox1:Clone()
Hitbox2.CFrame = Char.HumanoidRootPart.CFrame + Char.HumanoidRootPart.CFrame.LookVector * 0.8
Hitbox2.Parent = Char.HumanoidRootPart
local Huma = Char.Humanoid
local weld = Instance.new(“WeldConstraint”)
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = Hitbox2
weld.Parent = weld.Part0----
local Debounce = false
local HH = script:WaitForChild(“Animation2”)
local JJ = Huma:LoadAnimation(HH)
local CanAttack = Char:FindFirstChild(“CanAttack”)
local Stun = Char:FindFirstChild(“Stun”)
local Stun1 = game.ServerStorage:WaitForChild(“Stun”):Clone()

if CanAttack and Stun == nil then
Hitbox2.Touched:Connect(function(Hit)
local Char = player.Character
local Hume = Hit.Parent:FindFirstChild(“Humanoid”)
local HumeRooPa = Hit.Parent:FindFirstChild(“HumanoidRootPart”)
local player1 = game:GetService(“Players”):GetPlayerFromCharacter(Hit.Parent) or not Char
if Hit.Parent == Char or Hit.Parent == nil then return end
if Hit.Parent:FindFirstChild(“Accessory”) then
return nil
end
if player1 and Hit.Parent:FindFirstChild(“Humanoid”) and Hit.Parent:FindFirstChild(“HumanoidRootPart”) and Hit.Parent:IsA(“Model”) and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

  		Rep:FireClient(player1)
  		Stun1.Parent = Hit.Parent
  		local Hu1 = Hit.Parent:WaitForChild("Humanoid")
  		local Bovy = Instance.new("BodyVelocity")
  		Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
  		game.Debris:AddItem(Bovy,0.1)
  		Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 67
  		Bovy.MaxForce =  Vector3.new(10000,100000,10000)
  		game.Debris:AddItem(Bovy,0.1)
  		game.Debris:AddItem(Stun1,8)
  		Hume:TakeDamage(15)
  		Hitbox2:Destroy()
  		Debounce = false
  		weld.Part1:Destroy()
  		Hit.Parent.Humanoid:LoadAnimation(Scripta):Play()
  		if Hit.Parent:FindFirstChild("HitboxXD") then
  			game.Debris:AddItem(Hit.Parent:FindFirstChild("HitboxXD"),0)
  		end
  		
  	end
  	
  	if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

  		local Hu1 = Hit.Parent:WaitForChild("Humanoid")
  		Hu1:LoadAnimation(Scripta):Play()
  		local Bovy = Instance.new("BodyVelocity")
  		Bovy.MaxForce = Vector3.new(10000,100000,10000)
  		Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
  		game.Debris:AddItem(Bovy,0.1)
  		Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 67
  		Hume:TakeDamage(15)
  		Hitbox2:Destroy()
  		Debounce = false
  		weld.Part1:Destroy()

  	end
  	
  end)

end
wait(0.1)
weld.Part1:Destroy()
end)

Local Script

local Animation = script:WaitForChild(“Animation”)

local Animation2 = script:WaitForChild(“Animation2”)

local Player = game:GetService(“Players”).LocalPlayer

local Char = Player.Character

local Human = Char:WaitForChild(“Humanoid”)

local Hit = game.ReplicatedStorage:WaitForChild(“Hit”)

local HumanRoot = Char:WaitForChild(“HumanoidRootPart”)

local UIS = game:GetService(“UserInputService”)

local cooldown = 5

local Debounce = false

if Human.Died then

script.Disabled = true

end

UIS.InputBegan:Connect(function(input,IsTyping)

if not IsTyping and not Debounce then

if input.KeyCode == Enum.KeyCode.F then

Hit:FireServer()

Debounce = true

wait(1)

Debounce = false

end

end

end)

Stun script

game.ReplicatedStorage.P1.OnClientEvent:Connect(function()
local Player = game:GetService(“Players”).LocalPlayer
local Char = Player.Character
local Hum = Char:WaitForChild(“Humanoid”)
Hum.WalkSpeed = 0
Hum.JumpHeight = 0
wait(4)
Hum.WalkSpeed = 16
Hum.JumpHeight = 7.2

end)

This script is combat script btw.

I already committed them all. And they still not work.

what part is not working?, is not taking any damage?

does it show you any errors inside of the Developer Console when you are in game?

Did you enable use jump height? That may be why since most games use jumppower.

No, it dosen’t show any erors when in game