I disagree with the need to check the class because :GetPlayerFromCharacter()
will always return an instance of the class Player
if it’s not nil, hence rendering that bit useless.
Btw guys,Does the problem just because i using localscript?
I don’t think this is where the problem is emerging from, but I definitely suggest moving this to a server script, because it’ll be checking for every player not just one. There is a possibility that this is the root of the problem though.
Try just adding that
if Player then
--in group stuff and rest of code
end
That will fix it.
I recommend just copy and pasting the code into a script inside ServerScriptService. Also like @MrLonely1221 said, add the if Player then
thing if you haven’t already.
I can’t do that because there a ‘FireServer
’.
Would you mind showing us that part of the code so I can help you change it up? Mostly the part where the server receives it.
No need to have it under ServerScriptService, just have your script under your part. Also if you’re going to switch to the server, be aware of: .
Using this in a
Script
, as opposed to aLocalScript
, will not get you the most up-to-date information. If a player leaves a group while they are in the game, IsInGroup will still think they’re in that group until they leave. However, this does not happen when used with a LocalScript.
Remote events may be a workaround
I agree, but if he is using if Player then
then I really don’t have any other idea as to why this isn’t working.
This :
game.Workspace.GroupChest.TriggerPart.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit:FindFirstAncestorWhichIsA("Model") then
if Player then
if Player:IsInGroup(7104281) then -- Group ID
if hit.Name == "HumanoidRootPart" then
if ReadyToClaim == true then
local Coins = 1000
game.ReplicatedStorage.CoinGiver:FireServer(Coins)
game.Workspace.ChestModel.TimerPart.BillboardGui.ComeBackIn.Text = "Come back in"
game.ReplicatedStorage.GiveChestData:FireServer(MinutesYouWantItToBe, SecondsYouWantItToBe, GroupHours)
repeat
ReadyToClaim = false
if GroupHours >= 1 then
if seconds <= 0 then
if minutes <= 0 then
GroupHours = GroupHours - 1
minutes = 59
seconds = 59
else
minutes = minutes - 1
seconds = 59
end
else
seconds = seconds - 1
end
else
if seconds <= 0 then
minutes = minutes - 1
seconds = 59
else
seconds = seconds - 1
end
end
if GroupHours <= 9 then
if minutes <= 9 then
if seconds <= 9 then
timer.Text = tostring("").."0"..tostring(GroupHours)..":0"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring("").."0"..tostring(GroupHours)..":0"..tostring(minutes)..":"..tostring(seconds)
end
else
if seconds <= 9 then
timer.Text = tostring("").."0"..tostring(GroupHours)..":"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring("").."0"..tostring(GroupHours)..":"..tostring(minutes)..":"..tostring(seconds)
end
end
else
if minutes <= 9 then
if seconds <= 9 then
timer.Text = tostring(GroupHours)..":0"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(GroupHours)..":0"..tostring(minutes)..":"..tostring(seconds)
end
else
if seconds <= 9 then
timer.Text = tostring(GroupHours)..":"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(GroupHours)..":"..tostring(minutes)..":"..tostring(seconds)
end
end
end
wait(1)
until GroupHours == 0 and minutes == 0 and seconds == 0
timer.Text = "claim your reward!"
game.Workspace.ChestModel.TimerPart.BillboardGui.ComeBackIn.Text = "Ready to"
ReadyToClaim = true
game.ReplicatedStorage.GiveGroupData:FireServer(minutes, seconds, GroupHours)
end
end
end
end
end
end)
game.Workspace.GroupChest.TriggerPart.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit:FindFirstAncestorWhichIsA("Model"))
if Player then
if Player:IsInGroup(7104281) then -- Group ID
if hit.Name == "HumanoidRootPart" then
if ReadyToClaim == true then
local Coins = 1000
game.ReplicatedStorage.CoinGiver:FireServer(Coins)
game.Workspace.ChestModel.TimerPart.BillboardGui.ComeBackIn.Text = "Come back in"
game.ReplicatedStorage.GiveChestData:FireServer(MinutesYouWantItToBe, SecondsYouWantItToBe, GroupHours)
repeat
ReadyToClaim = false
if GroupHours >= 1 then
if seconds <= 0 then
if minutes <= 0 then
GroupHours = GroupHours - 1
minutes = 59
seconds = 59
else
minutes = minutes - 1
seconds = 59
end
else
seconds = seconds - 1
end
else
if seconds <= 0 then
minutes = minutes - 1
seconds = 59
else
seconds = seconds - 1
end
end
if GroupHours <= 9 then
if minutes <= 9 then
if seconds <= 9 then
timer.Text = tostring("").."0"..tostring(GroupHours)..":0"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring("").."0"..tostring(GroupHours)..":0"..tostring(minutes)..":"..tostring(seconds)
end
else
if seconds <= 9 then
timer.Text = tostring("").."0"..tostring(GroupHours)..":"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring("").."0"..tostring(GroupHours)..":"..tostring(minutes)..":"..tostring(seconds)
end
end
else
if minutes <= 9 then
if seconds <= 9 then
timer.Text = tostring(GroupHours)..":0"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(GroupHours)..":0"..tostring(minutes)..":"..tostring(seconds)
end
else
if seconds <= 9 then
timer.Text = tostring(GroupHours)..":"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(GroupHours)..":"..tostring(minutes)..":"..tostring(seconds)
end
end
end
wait(1)
until GroupHours == 0 and minutes == 0 and seconds == 0
timer.Text = "claim your reward!"
game.Workspace.ChestModel.TimerPart.BillboardGui.ComeBackIn.Text = "Ready to"
ReadyToClaim = true
game.ReplicatedStorage.GiveGroupData:FireServer(minutes, seconds, GroupHours)
end
end
end
end
end)
Still doesnt work yet, i already finished made ‘Non Group’ chest,where if player touch part,the counter start,but in this(Group chest) i touched the part,but the counter doenst start yet,and also there no error in output
I just copy pasted you code and tried my best to get the code to what we were saying to do, grabbing the player character with hit:FindFirstAncestor… then the if Player then
I could have messed up when typing it because I did it in the editor here on the forum so you may want to double check it.