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:
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!