Studio and Roblox Player version of games are different

My Roblox game works very well in Studio but it breaks in the Client.
For example, an NPC is supposed to get shot and then trip, get back up, and run around. It also chats “Ow” once in a while
It also gets highlighted when the mouse goes over it
In studio it works fine, but in Roblox Player it doesn’t chat at all, runs around while in the sitting animation, and doesn’t get highlighted
It’s not a code problem because again, it works fine in Studio
This might be game breaking and hopefully doesn’t happen to other people so please help

it’s not letting me upload the videos / examples for some reason

Also, I did make sure they are on the same version and the Studio version is published to roblox.

Just because it works in studio, doesn’t mean it’s not a code problem.

Are you referencing a player in your NPC script? Are you waiting for some event in your script? Errors can happen where there are race conditions in your script, which only work in studio.

Could you post the code too?

Panic Script

local hum = script.Parent.Parent.Parent:WaitForChild("Humanoid")
local curhp = hum.Health

local panic = false

hum.HealthChanged:Connect(function(newhp)
	if curhp < newhp then return end --new hp greater than curren, nothing
	local difference = math.abs(curhp - newhp)
	if difference > 4.9 then
		panic = not panic
		if panic == true then
			script.Parent.Parent.Parent:WaitForChild("Values"):WaitForChild("panic").Value = true
			game.Chat:Chat(script.Parent.Parent.Parent:WaitForChild("Head"), "Ouch!", "White")
			hum.Jump = true
			wait(0.1)
			hum.Sit = true
			hum.WalkSpeed = 20
			wait(math.random(1,5))
			hum.Jump = true
			wait(math.random(7,20))
			hum.WalkSpeed = 12
			script.Parent.Parent.Parent:WaitForChild("Values"):WaitForChild("panic").Value = false
			panic = false
		end
	end
	curhp = newhp

Chatting script

local head = script.Parent.Parent.Parent:WaitForChild("Head")
local ChatService = game:GetService("Chat")
local possibleWords = {
	"Oof!",
	"Yowch!",
	"Ouchie!",
	"Oh no!",
	"Oohhh!",
	"It hurts!",
	"Ow ow ow!"
}

while wait() do
	if script.Parent.Value == true and script.Parent.Parent.Parent:WaitForChild("Humanoid").Health ~= 0 then
		repeat 
			ChatService:Chat(head, possibleWords[math.random(1, #possibleWords)], "White")
			wait(math.random(2,5))
		until script.Parent.Value == false
	end
end

StarterPlayer highlight script (Gui works fine so ignore that)

local emotion = nil

local vName
local vHealth
local vEmotion
local vMoney

local infoGui
local nameGui
local healthGui
local emotionGui
local moneyGui

local function getName(t)
	vName = t.Parent:WaitForChild("Values"):WaitForChild("name")
	local nameGui = script.Parent.Parent.PlayerGui:WaitForChild("HUD"):WaitForChild("Frame"):WaitForChild("name")
	nameGui.Text = vName.Value
end
local function getHealth(t)
	vHealth = t.Parent:WaitForChild("Values"):WaitForChild("health")
	local healthGui = script.Parent.Parent.PlayerGui:WaitForChild("HUD"):WaitForChild("Frame"):WaitForChild("health")
	healthGui.Text = vHealth.Value.."/200"
end
local function getEmotion(t)
	vEmotion = t.Parent:WaitForChild("Values"):WaitForChild("emotion")
	local emotionGui = script.Parent.Parent.PlayerGui:WaitForChild("HUD"):WaitForChild("Frame"):WaitForChild("emotion")
	emotionGui.Text = vEmotion.Value
end
--[[local function getMoney(t)
	vName = t.Parent:WaitForChild("Values"):WaitForChild("name")
end]]--

local visible = false


while wait(0.15) do
	local Target = mouse.Target
	if Target and Target.Parent:FindFirstChild("Humanoid") then
		local infoGui = script.Parent.Parent.PlayerGui:WaitForChild("HUD"):WaitForChild("Frame")
		infoGui.Visible = true
		print("We got "..Target.Parent.Name.." from the mouse!")
		sb = Target.Parent:FindFirstChild("selectbox")
		sb.Enabled = true
		emotion = Target.Parent.Head:FindFirstChild("emotion")
		emotion.Enabled = true
		getName(Target)
		getHealth(Target)
		getEmotion(Target)
	else
		
		if sb ~= nil then
			sb.Enabled = false
			emotion.Enabled = false
			local infoGui = script.Parent.Parent.PlayerGui:WaitForChild("HUD"):WaitForChild("Frame")
			infoGui.Visible = false
		end
	end
end

never mind i don’t know what happened, it suddenly works now??

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.