My game will work in Studio but not in Game

I want to make my game work.

It wont work in studio but will work when I go to the website and press play on my game.
(Sorry for the lag I can’t fix that. It is just the video)
In Studio:

In Game:

Google

I am trying to make my eating game. But when I play in game actually it just wont play the animation and/or eat it/play the sound. I have made my LocalScript inside of StarterGui and PlayerGui it did not work. I have used RemoteEvents and Accessories for None glitch reasons.

[LocalScript : StarterGui]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local player = Players.LocalPlayer

while true do wait(0.5)
	if player.Character then
		break
	end
end

local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local Items = ReplicatedStorage:WaitForChild("Items")
local MainEvents = ReplicatedStorage:WaitForChild("MainEvents")
local PlayerGui = player:WaitForChild("PlayerGui")
local EatEvent = MainEvents:WaitForChild("EatEvent")
local SoundEffect = MainEvents:WaitForChild("SoundEffect")

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		local eatingAnim = humanoid:LoadAnimation(script:WaitForChild("EatingAnimation"))
		for _,itemName in pairs(Items:GetChildren()) do
			for _,itemName2 in pairs(character:GetChildren()) do
				if  itemName2.Name == itemName.Name then
					eatingAnim:Play()
					
					eatingAnim:GetMarkerReachedSignal("EatSound"):Connect(function()
						SoundEffect:FireServer()
					end)
					
					eatingAnim.Stopped:Wait()
					EatEvent:FireServer(itemName2)
				end
			end
		end
	end
end)

[ServerScript : ServerScriptService]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Items = ReplicatedStorage:FindFirstChild("Items")

for _,instance in pairs(workspace.Map:GetDescendants()) do
	if instance:IsA("ClickDetector") then
		instance.MouseClick:Connect(function(player)
			local item = instance:FindFirstChild("Item")
			
			if Items:FindFirstChild(item.Value) and not player:WaitForChild("PlayerGui"):WaitForChild("Holding").Value then
				local accessory = Items[item.Value]
				
				local character = player.Character
				local humanoid = character:FindFirstChildWhichIsA("Humanoid")
				
				if humanoid then
					local clone = accessory:Clone()
					
					local attachment = Instance.new("Attachment")
					attachment.CFrame = clone.Handle.CFrame * CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(90), math.rad(90), 0)
					attachment.Name = "RightGripAttachment"
					attachment.Parent = clone.Handle
					
					player:WaitForChild("PlayerGui"):WaitForChild("Holding").Value = true
					humanoid:AddAccessory(clone)
				end
			end
		end)
	end
end

[ServerScript : Workspace (so sound works)]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MainEvents = ReplicatedStorage:FindFirstChild("MainEvents")
local EatEvent = MainEvents:FindFirstChild("EatEvent")
local SoundEffect = MainEvents:FindFirstChild("SoundEffect")

EatEvent.OnServerEvent:Connect(function(Player,Item)
	Item:Destroy()
	Player:WaitForChild("PlayerGui"):WaitForChild("Holding").Value = false
end)

SoundEffect.OnServerEvent:Connect(function(Player)
	script.EatingSound:Play()
end)

Thank you for your time!

3 Likes

Are there any errors in output?

No there is no errors at all in the output I even checked the DevConsole no errors

Might just be a Animation issue

If the Animation isn’t owned by you, you won’t be able to play it while in-game (Hence why you have to create it yourself)

If that isn’t the case, have you tried setting the AnimationPriority to Action?

this happened to me before when i used a local script for something so maybe thats why not a 100% sure tho

I created the animation on a R6 dummy rig and all the characters are forced to R6 and yes the Priority is set to Action

Proof:


Do you think I coded it wrong or anything? Because I tried with my friend the Sand doesn’t even dissapear.

Is the game published, i assume it is but just checking.

Yes the game is Public and Published. I even checked right now. It is all fine and published.

I would love to know how to fix this because if i’m not able to I have to get rid of my good idea ;-;

Yeah i am sorry but i have absolutely no idea on how to fix that.

Is the game owned by a group? If so, the animation should be too, if not, I don’t know what it can be.

4 Likes

ohhhh okay well you fixed it thank you.

2 Likes