Hello,
I am just being dumb with remote events and running into simple stuff like this. I’m having an issue where Mobile Players are clicking the UI button, which applies to all players instead of just them.
Purpose of script: Let the player meditate/play the animation.
What I have right now -
GUIBUTTON -
--[[ SERVICES ]]--
--local ContextActionService = game:GetService("ContextActionService")
local RepStorage = game:GetService("ReplicatedStorage")
--[[ VARIABLES ]]--
local Player = game.Players.LocalPlayer
local character = Player.Character
local anim = script:WaitForChild("Meditate")
local animationPlaying = false
local a
local RemoteEvent = RepStorage:WaitForChild("Remotes").Meditate
local SprintEvent = RepStorage:WaitForChild("Remotes").Sprint
local sound = game.ReplicatedStorage:WaitForChild("Sounds2").Pop
local MeditateButton = script.Parent:WaitForChild("Meditate")
local SprintButton = script.Parent:WaitForChild("Sprint")
--[[ MEDITATE ]]--
MeditateButton.Button.MouseButton1Click:Connect(function(inputObject)
sound:Play()
RemoteEvent:FireServer(Player)
end)
--[[ SPRINT ]]--
SprintButton.Button.TouchLongPress:Connect(function (TouchPositions, TouchState)
if TouchState == Enum.UserInputState.Begin then
SprintEvent:FireServer(Player, "On")
elseif TouchState == Enum.UserInputState.End then
SprintEvent:FireServer(Player, "Off")
end
end)
ServerScriptService -
--[[ SERVICES ]]--
local RepStorage = game:GetService("ReplicatedStorage")
--[[ VARIABLES ]]--
local RemoteEvent = RepStorage:WaitForChild("Remotes").Meditate
--[[ MEDITATE ]]--
game.Players.PlayerAdded:Connect(function(plr)
RemoteEvent.OnServerEvent:Connect(function()
RemoteEvent:FireClient(plr)
end)
end)
StarterCharacterScripts -
RemoteEvent.OnClientEvent:Connect(function(plr)
if animationPlaying == false then
a = character.Humanoid:LoadAnimation(anim)
a:Play()
character.HumanoidRootPart.Anchored = true
animationPlaying = true
else
a:Stop()
character.HumanoidRootPart.Anchored = false
animationPlaying = false
end
end)
Keep In mind I have two buttons, one for meditate, and one for sprint. Each script is located inside StarterCharacterScripts (for pc users)…
How can I fix this? Right now it’s applying to the whole server.